NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/43937: S_*() macros in sys/stat.h are missing parenthesis
>Number: 43937
>Category: lib
>Synopsis: S_*() macros in sys/stat.h are missing parenthesis
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Oct 04 11:15:00 +0000 2010
>Originator: Ævar Arnfjörð Bjarmason
>Release: 5.0.2
>Organization:
>Environment:
NetBSD conker 5.0.2 NetBSD 5.0.2 (GENERIC) #0: Sat Feb 6 13:44:19 UTC 2010
builds%b8.netbsd.org@localhost:/home/builds/ab/netbsd-5-0-2-RELEASE/amd64/201002061851Z-obj/home/builds/ab/netbsd-5-0-2-RELEASE/src/sys/arch/amd64/compile/GENERIC
amd64
>Description:
The S_*() macros in /usr/include/sys/stat.h don't apply parenthesis to
their arguments:
$ grep '#define.*S_.*(m ' /usr/include/sys/stat.h
#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_ISLNK(m) ((m & _S_IFMT) == _S_IFLNK) /* symbolic link */
#define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK) /* socket */
#define S_ISWHT(m) ((m & _S_IFMT) == _S_IFWHT) /* whiteout */
So calling e.g. S_ISREG(0644) means:
S_IFREG | 0644 & _S_IFMT
On NetBSD but:
(S_IFREG | 0644) & _S_IFMT
On Linux.
Since bitwise AND (&) has precedence over bitwise OR that introduces a
logic error.
>How-To-Repeat:
Look at /usr/include/sys/stat.h
>Fix:
You should put parenthesis around m to avoid this issue:
$ grep S_ISREG /usr/include/sys/stat.h
#define S_ISREG(m) ((m & _S_IFMT) == _S_IFREG) /* regular file */
$ grep S_ISREG /usr/include/linux/stat.h
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
Home |
Main Index |
Thread Index |
Old Index