This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/14362] New: Incorrect ioctl declaration


http://sourceware.org/bugzilla/show_bug.cgi?id=14362

             Bug #: 14362
           Summary: Incorrect ioctl declaration
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: unassigned@sourceware.org
        ReportedBy: torvalds@linux-foundation.org
                CC: drepper.fsp@gmail.com
    Classification: Unclassified


Both SuS and the man-pages agree: the correct declaration for ioctl() is

   extern int ioctl(int fd, int request, ...);

but glibc headers incorrectly have "unsigned long" for the request. 

This means that this simple C program results in an incorrect type conflict
error:

   #include <sys/ioctl.h>
   extern int ioctl(int fd, int request, ...);

even though the declaration clearly matches documentation.

Perhaps more importantly, it's misleading for anybody who actually reads the
header files. That's rare, but still.. We had this discussion on the subsurface
mailing list, because OS X has the same buggy declaration, and what is worse,
the OS X kernel is apparently buggy too, because doing

   int action = (level ? TIOCSBRK : TIOCCBRK);
   ...
   ioctl(fd, action, ...);

will sign-extend the 'int' into 'unsigned long', and the OS X FreeBSD-based
kernel apparently actually looks at all 64 bits of an 'unsigned long' when it
does things, leading to actual bugs (ie ioctl returning ENOTTY because the
sign-extended 64-bit value is not recognized).

So having "unsigned long" in there can result in actual bugs. You don't see
this on Linux, because 64-bit Linux will correctly truncate the request value
to 32 bits (and then internally uses 'unsigned' to make sure no sign extension
happens, but that's a separate issue).

So please fix the ioctl() declaration. "unsigned long" is misleading and
actively incorrect and can cause bugs on non-Linux operating systems.

In case anybody uses glibc on OS X, I would suggest doing

   int ioctl(int fd, int __request, ...)
   {
       unsigned long request = (unsigned int) __request;
       ...

to avoid the OS X bug.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]