Bug 15347 - __FD_MASK triggers undefined behavior
Summary: __FD_MASK triggers undefined behavior
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: 2.20
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-08 13:59 UTC by Florian Weimer
Modified: 2014-06-13 18:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2013-04-08 13:59:53 UTC
typedef long int __fd_mask;
#define __FD_MASK(d)    ((__fd_mask) 1 << ((d) % __NFDBITS))

1 can be shifted into the sign position, which isn't legal C.

I think we should just use 1UL and cast the result of the shift.
Comment 1 Florian Weimer 2014-02-26 09:13:18 UTC
Fixed in commit 4cbf380ce948ca15a965a78f0c1a092cf5956792.