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: sebastien Couret <sebastien dot couret at elios-informatique dot fr>
- To: ecos-patches at sources dot redhat dot com
- Cc: Andrew Lunn <andrew at lunn dot ch>
- Date: Thu, 25 Mar 2004 12:21:56 +0100
- Subject: Re: [ECOS] PATCH 4 "No checking of index while accessing file descriptor table might lead to a crash"
- Organization: Elios Informatique
- References: <MELELIOS5BzC533iJ0h00000496@melelios.dmz.elios-informatique.fr> <MELELIOSXmM8JWfwkJF00000001@melelios.dmz.elios-informatique.fr> <20040315165922.GE20801@lunn.ch>
- Reply-to: sebastien dot couret at elios-informatique dot fr
On Monday 15 March 2004 17:59, you wrote:
> 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.
>
Hi all,
As suggested by Andrew, I have revisited my patch :
$ diff -a -w -u -r io/fileio/current/src/v1.5 io/fileio/current/src/fd.cxx
--- io/fileio/current/src/v1.5/fd.cxx Wed Mar 10 14:40:51 2004
+++ io/fileio/current/src/fd.cxx Thu Mar 25 12:10:20 2004
@@ -175,7 +175,10 @@
static int fd_close( int fd )
{
int error = 0;
- cyg_file *fp = desc[fd];
+ cyg_file *fp;
+
+ CYG_ASSERT(((0 < fd) && (fd<CYGNUM_FILEIO_NFD)),"fd out of range");
+ fp= desc[fd];
if( fp != FD_ALLOCATED && fp != NULL)
{
@@ -202,6 +205,7 @@
{
int fd;
+ CYG_ASSERT(((0 < low) && (low<CYGNUM_FILEIO_NFD)),"fd out of range");
FILEIO_MUTEX_LOCK(fdlock);
for( fd = low; fd < CYGNUM_FILEIO_NFD; fd++ )
@@ -244,6 +248,8 @@
{
int error;
+ CYG_ASSERT(((0 < fd) && (fd<CYGNUM_FILEIO_NFD)),"fd out of range");
+
FILEIO_MUTEX_LOCK(fdlock);
error = fd_close( fd );
@@ -266,6 +272,8 @@
__externC cyg_file *cyg_fp_get( int fd )
{
+ CYG_ASSERT(((0 < fd) && (fd<CYGNUM_FILEIO_NFD)),"fd out of range");
+
FILEIO_MUTEX_LOCK(fdlock);
cyg_file *fp = desc[fd];
@@ -330,6 +338,8 @@
__externC int dup( int fd )
{
+ CYG_ASSERT(((0 < fd) && (fd<CYGNUM_FILEIO_NFD)),"fd out of range");
+
cyg_file *fp = cyg_fp_get( fd );
if( fp == NULL )
@@ -358,6 +368,9 @@
__externC int dup2( int fd, int fd2 )
{
+ CYG_ASSERT(((0 < fd) && (fd<CYGNUM_FILEIO_NFD)),"fd out of range");
+ CYG_ASSERT(((0 < fd2) && (fd2<CYGNUM_FILEIO_NFD)),"fd2 out of range");
+
if( fd2 == fd ) return fd2;
if( fd2 < 0 || fd2 >= OPEN_MAX )
And here comes the ChangeLog Modification :
$ diff -a -w -u -r io/fileio/current/ChangeLog
io/fileio/current/ChangeLog.1.42
--- io/fileio/current/ChangeLog Thu Mar 25 12:06:24 2004
+++ io/fileio/current/ChangeLog.1.42 Thu Mar 25 12:15:31 2004
@@ -1,3 +1,8 @@
+2004-03-25 Sebastien Couret <sebastien.couret@elios-informatique.fr>
+
+ * src/fd.cxx: Added CYG_ASSERT bound checking for file descriptor
number
+ (0<fd<CYGNUM_FILEIO_NFD).
+
2004-03-12 Jonathan Larmour <jifl@eCosCentric.com>
* src/fio.h: If no POSIX then CYG_FILEIO_DELIVER_SIGNALS
Hope this is a better way of posting a patch.
Have a nice day.