This is the mail archive of the libc-alpha@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]

[PATCH] Avoid undefined behavior in __FD_MASK


Shifting 1 into the sign position is supported by current GCC versions, but the manual explicitly says this is subject to change. __fd_mask should really be an unsigned type, but changing that is more risky. The remaining bit operations should be safe.

Tested on x86_64-redhat-linux-gnu.

--
Florian Weimer / Red Hat Product Security Team
2013-04-09  Florian Weimer  <fweimer@redhat.com>

	[BZ #15347]
	* misc/sys/select.h (__FD_MASK): Avoid signed integer overflow.

diff --git a/misc/sys/select.h b/misc/sys/select.h
index 21351fe..90be5ee 100644
--- a/misc/sys/select.h
+++ b/misc/sys/select.h
@@ -58,7 +58,7 @@ typedef long int __fd_mask;
 /* It's easier to assume 8-bit bytes than to get CHAR_BIT.  */
 #define __NFDBITS	(8 * (int) sizeof (__fd_mask))
 #define	__FD_ELT(d)	((d) / __NFDBITS)
-#define	__FD_MASK(d)	((__fd_mask) 1 << ((d) % __NFDBITS))
+#define	__FD_MASK(d)	((__fd_mask) (1UL << ((d) % __NFDBITS)))
 
 /* fd_set for select and pselect.  */
 typedef struct
-- 
1.8.1.4


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