This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: [ECOS] PATCH 4 "No checking of index while accessing file descriptor table might lead to a crash"
- From: Andrew Lunn <andrew at lunn dot ch>
- To: sebastien Couret <sebastien dot couret at elios-informatique dot fr>
- Cc: ecos-patches at sources dot redhat dot com
- Date: Mon, 15 Mar 2004 17:59:22 +0100
- Subject: Re: [ECOS] PATCH 4 "No checking of index while accessing file descriptor table might lead to a crash"
- References: <MELELIOS5BzC533iJ0h00000496@melelios.dmz.elios-informatique.fr> <50843.62.252.32.8.1078922549.squirrel@www.chez-thomas.org> <MELELIOSXmM8JWfwkJF00000001@melelios.dmz.elios-informatique.fr>
Hi Sebastien
The rest of eCos uses the macro CYG_ASSERT() rather than assert().
Please could you change your patch to use this macro, eg something
like
CYG_ASSERT((0 < fd) && (fd<CYGNUM_FILEIO_NFD))","fd out of range");
Please also include a ChangeLog entry with your patch.
On Wed, Mar 10, 2004 at 03:03:41PM +0100, sebastien Couret wrote:
> I would like to give a patch concerning the following issue :
>
> "
> These functions will probably crash, if u pass an fd
> >=CYGNUM_FILEIO_NFD to them.
>
> ?fd_close
> ?cyg_fd_assign
> ?cyg_fd_free
> ?cyg_fp_get
> cyg_fd_alloc (with negative parameter low)
> "
>
> Here 's the patch : (sorry my CVS access is rectricted : v1.5/fd.cxx is the
> file v1.5 I just got on CVSweb)
>
> <
> diff -a -w -u -r v1.5 fd.cxx
> --- v1.5/fd.cxx Wed Mar 10 14:40:51 2004
> +++ fd.cxx Wed Mar 10 14:47:09 2004
> @@ -62,6 +62,7 @@
> #endif
> #include <cyg/infra/cyg_trac.h> // tracing macros
> #include <cyg/infra/cyg_ass.h> // assertion macros
> +#include <assert.h> // asserts
>
> #include "fio.h" // Private header
>
> @@ -175,7 +176,10 @@
> static int fd_close( int fd )
> {
> int error = 0;
> - cyg_file *fp = desc[fd];
> + cyg_file *fp;
> +
> + assert(0<fd<CYGNUM_FILEIO_NFD);
I don't think this does what you think it does. It will first evaluate
0 < fd
which is boolean. You then compare this boolean value against
CYGNUM_FILEIO_NFD. I'm supprised you did not get a warning from the
compile about this. I assume you tested your patch with asserts
enabled?
Andrew