NetBSD-Bugs archive

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

lib/41919: [dM] S_IS*() insufficiently parenthesized



>Number:         41919
>Category:       lib
>Synopsis:       [dM] S_IS*() insufficiently parenthesized
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 22 22:05:00 +0000 2009
>Originator:     der Mouse
>Release:        NetBSD 4.0.1
>Organization:
        Dis-
>Environment:
System: NetBSD Laptop-401.Rodents-Montreal.ORG 4.0.1 NetBSD 4.0.1 (GEN401_WD0F) 
#0: Mon Jul 20 23:52:41 EDT 2009 
mouse%Laptop-401.Rodents-Montreal.ORG@localhost:/home/mouse/kbuild/GEN401_WD0F 
i386
Architecture: i386
Machine: i386
>Description:
        The S_ISDIR(), S_ISCHR(), etc, macros in <sys/stat.h> are
        insufficiently parenthesized, leading to breakage when the
        argument is of the form xxx|yyy.  (This is not a hypothetical
        usage case; I tripped over it trying to build some third-party
        code.)
>How-To-Repeat:
        Compile code using such an argument, as in

        #include <sys/stat.h>
        int foo(int x)
        {
         return(S_ISREG(x|0644)?2:3);
        }

        and observe it doesn't behave the way it should.  Or, compile
        with -Wall and get a "suggest parentheses around arithmetic in
        operand of |" warning.
>Fix:
        Add parens.

        Diff relative to stat.h,v 1.54 (4.0.1's stat.h, it being 4.0.1
        I tripped over this on); other versions' <sys/stat.h>s need
        similar changes, but this diff may not apply painlessly.

        --- OLD/stat.h  2006-02-24 17:01:30.000000000 -0500
        +++ NEW/stat.h  2009-08-22 17:53:01.000000000 -0400
        @@ -168,21 +168,21 @@
         #define        S_ARCH2 _S_ARCH2
         #endif
         
        -#define        S_ISDIR(m)      ((m & _S_IFMT) == _S_IFDIR)     /* 
directory */
        -#define        S_ISCHR(m)      ((m & _S_IFMT) == _S_IFCHR)     /* char 
special */
        -#define        S_ISBLK(m)      ((m & _S_IFMT) == _S_IFBLK)     /* 
block special */
        -#define        S_ISREG(m)      ((m & _S_IFMT) == _S_IFREG)     /* 
regular file */
        -#define        S_ISFIFO(m)     ((m & _S_IFMT) == _S_IFIFO)     /* fifo 
*/
        +#define        S_ISDIR(m)      (((m) & _S_IFMT) == _S_IFDIR)   /* 
directory */
        +#define        S_ISCHR(m)      (((m) & _S_IFMT) == _S_IFCHR)   /* char 
special */
        +#define        S_ISBLK(m)      (((m) & _S_IFMT) == _S_IFBLK)   /* 
block special */
        +#define        S_ISREG(m)      (((m) & _S_IFMT) == _S_IFREG)   /* 
regular file */
        +#define        S_ISFIFO(m)     (((m) & _S_IFMT) == _S_IFIFO)   /* fifo 
*/
         #if ((_POSIX_C_SOURCE - 0) >= 200112L) || defined(_XOPEN_SOURCE) || \
             defined(_NETBSD_SOURCE)
        -#define        S_ISLNK(m)      ((m & _S_IFMT) == _S_IFLNK)     /* 
symbolic link */
        +#define        S_ISLNK(m)      (((m) & _S_IFMT) == _S_IFLNK)   /* 
symbolic link */
         #endif
         #if ((_POSIX_C_SOURCE - 0) >= 200112L) || ((_XOPEN_SOURCE - 0) >= 600) 
|| \
             defined(_NETBSD_SOURCE)
        -#define        S_ISSOCK(m)     ((m & _S_IFMT) == _S_IFSOCK)    /* 
socket */
        +#define        S_ISSOCK(m)     (((m) & _S_IFMT) == _S_IFSOCK)  /* 
socket */
         #endif
         #if defined(_NETBSD_SOURCE)
        -#define        S_ISWHT(m)      ((m & _S_IFMT) == _S_IFWHT)     /* 
whiteout */
        +#define        S_ISWHT(m)      (((m) & _S_IFMT) == _S_IFWHT)   /* 
whiteout */
         #endif
         
         #if defined(_NETBSD_SOURCE)

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

>Unformatted:
        UTSLing makes me think this applies to everything from 1.4T
        through -current as well.


Home | Main Index | Thread Index | Old Index