summaryrefslogtreecommitdiff
path: root/include/asterisk/select.h
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2011-04-26 19:38:41 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2011-04-26 19:38:41 +0000
commit47a6dacf290e0a18622ac63645106616283c3500 (patch)
tree903f24701bb0b58f1fa5f53e8175f16275274ce4 /include/asterisk/select.h
parentabe0351e1293c8d18d5cd4d64e8cd4066bcbdf2e (diff)
Merged revisions 315503 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r315503 | tilghman | 2011-04-26 14:32:50 -0500 (Tue, 26 Apr 2011) | 28 lines Merged revisions 315502 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r315502 | tilghman | 2011-04-26 14:22:52 -0500 (Tue, 26 Apr 2011) | 21 lines Merged revisions 315501 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r315501 | tilghman | 2011-04-26 14:18:46 -0500 (Tue, 26 Apr 2011) | 14 lines Fix the bounds-checking code. The code that set the bit within the select bitfield was correct, but the bounds-checking code was not. The change to that line uses the new _bitsize macro for clarity. Also, FD_ZERO macro did not zero-out anything but the first word of the bitfield, so this could have caused problems with modules using that macro with the expanded bitfield. (closes issue #18773) Reported by: jamicque Patches: 20110423__issue18773.diff.txt uploaded by tilghman (license 14) Tested by: chris-mac ........ ................ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@315504 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/select.h')
-rw-r--r--include/asterisk/select.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/include/asterisk/select.h b/include/asterisk/select.h
index a8f7c3c60..d6d34fbbd 100644
--- a/include/asterisk/select.h
+++ b/include/asterisk/select.h
@@ -43,12 +43,14 @@ typedef struct {
TYPEOF_FD_SET_FDS_BITS fds_bits[ast_FDMAX / 8 / SIZEOF_FD_SET_FDS_BITS]; /* 32768 bits */
} ast_fdset;
+#define _bitsize(a) (sizeof(a) * 8)
+
#undef FD_ZERO
#define FD_ZERO(a) \
do { \
TYPEOF_FD_SET_FDS_BITS *bytes = (TYPEOF_FD_SET_FDS_BITS *) a; \
int i; \
- for (i = 0; i < sizeof(*(a)) / SIZEOF_FD_SET_FDS_BITS; i++) { \
+ for (i = 0; i < ast_FDMAX / _bitsize(TYPEOF_FD_SET_FDS_BITS); i++) { \
bytes[i] = 0; \
} \
} while (0)
@@ -56,8 +58,10 @@ typedef struct {
#define FD_SET(fd, fds) \
do { \
TYPEOF_FD_SET_FDS_BITS *bytes = (TYPEOF_FD_SET_FDS_BITS *) fds; \
- if (fd / sizeof(*bytes) + ((fd + 1) % sizeof(*bytes) ? 1 : 0) < sizeof(*(fds))) { \
- bytes[fd / (sizeof(*bytes) * 8)] |= ((TYPEOF_FD_SET_FDS_BITS) 1) << (fd % (sizeof(*bytes) * 8)); \
+ /* 32bit: FD / 32 + ((FD + 1) % 32 ? 1 : 0) < 1024 */ \
+ /* 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)); \
} else { \
fprintf(stderr, "FD %d exceeds the maximum size of ast_fdset!\n", fd); \
} \