mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
Simplify and fix conditional in FD_SET.
FD_SET contains a conditional statement to protect against buffer overruns. The statement was overly complicated and prevented use of the last array element of ast_fdset. We now just verify the fd is less than ast_FDMAX. Change-Id: I41895c0b497b052aef5bf49d75c817c48b326f40
This commit is contained in:
@@ -58,9 +58,7 @@ typedef struct {
|
|||||||
#define FD_SET(fd, fds) \
|
#define FD_SET(fd, fds) \
|
||||||
do { \
|
do { \
|
||||||
TYPEOF_FD_SET_FDS_BITS *bytes = (TYPEOF_FD_SET_FDS_BITS *) fds; \
|
TYPEOF_FD_SET_FDS_BITS *bytes = (TYPEOF_FD_SET_FDS_BITS *) fds; \
|
||||||
/* 32bit: FD / 32 + ((FD + 1) % 32 ? 1 : 0) < 1024 */ \
|
if (fd < ast_FDMAX) { \
|
||||||
/* 64bit: FD / 64 + ((FD + 1) % 64 ? 1 : 0) < 512 */ \
|
|
||||||
if (fd / _bitsize(*bytes) + ((fd + 1) % _bitsize(*bytes) ? 1 : 0) < sizeof(*(fds)) / SIZEOF_FD_SET_FDS_BITS) { \
|
|
||||||
bytes[fd / _bitsize(*bytes)] |= ((TYPEOF_FD_SET_FDS_BITS) 1) << (fd % _bitsize(*bytes)); \
|
bytes[fd / _bitsize(*bytes)] |= ((TYPEOF_FD_SET_FDS_BITS) 1) << (fd % _bitsize(*bytes)); \
|
||||||
} else { \
|
} else { \
|
||||||
fprintf(stderr, "FD %d exceeds the maximum size of ast_fdset!\n", fd); \
|
fprintf(stderr, "FD %d exceeds the maximum size of ast_fdset!\n", fd); \
|
||||||
|
Reference in New Issue
Block a user