bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash mishandles /dev/fd/4294967296 when emulating /dev/fd


From: Paul Eggert
Subject: bash mishandles /dev/fd/4294967296 when emulating /dev/fd
Date: Thu, 12 Apr 2001 14:56:23 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8' 
-DCONF_VENDOR='sun' -DSHELL  -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib 
-I/opt/reb/include -g -O2 -Wall
uname output: SunOS shade.twinsun.com 5.8 Generic_108528-06 sun4u sparc 
SUNW,Ultra-1
Machine Type: sparc-sun-solaris2.8

Bash Version: 2.05
Patch Level: 0
Release Status: release

Description:
        I found this bug by code inspection.

        When emulating /dev/fd, test_stat doesn't check for overflow
        when parsing the integer in /dev/fd/4294967296; this causes it
        to test the wrong file descriptor.  Also (and I think this is a nit)
        errno is set to the wrong value.

Repeat-By:

Fix:
2001-04-12  Paul Eggert  <eggert@twinsun.com>

        * test.c (test_stat): When emulating /dev/fd/NNN, report
        ENOENT for files that are not open, not EBADF.  Check for
        overflow, so that we don't improperly succeed for
        /dev/fd/4294967296.

===================================================================
RCS file: RCS/test.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- test.c      2001/03/08 13:52:45     2.5
+++ test.c      2001/04/12 21:50:50     2.5.0.1
@@ -178,13 +178,14 @@ test_stat (path, finfo)
     {
 #if !defined (HAVE_DEV_FD)
       long fd;
-      if (legal_number (path + 8, &fd))
-       return (fstat ((int)fd, finfo));
-      else
+      if (legal_number (path + 8, &fd) && fd == (int) fd)
        {
-         errno = EBADF;
-         return (-1);
+         int r = fstat ((int) fd, finfo);
+         if (r == 0 || errno != EBADF)
+           return (r);
        }
+      errno = ENOENT;
+      return (-1);
 #else
   /* If HAVE_DEV_FD is defined, DEV_FD_PREFIX is defined also, and has a
      trailing slash.  Make sure /dev/fd/xx really uses DEV_FD_PREFIX/xx.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]