summaryrefslogtreecommitdiffstats
path: root/libc/include
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-10-03 14:08:39 -0700
committerNick Kralevich <nnk@google.com>2013-10-03 15:45:10 -0700
commit7943df62f70f686b0c77532f6617b47255d75763 (patch)
tree13dfe2af815383802fe91f3192f4573ac13eb210 /libc/include
parent6088047a64abb1e8a27fcb9868b00a630fbdfed4 (diff)
downloadbionic-7943df62f70f686b0c77532f6617b47255d75763.zip
bionic-7943df62f70f686b0c77532f6617b47255d75763.tar.gz
bionic-7943df62f70f686b0c77532f6617b47255d75763.tar.bz2
Check memory size on FD_* functions
Make sure the buffer we're dealing with has enough room. Might as well check for memory issues while we're here, even though I don't imagine they'll happen in practice. Change-Id: I0ae1f0f06aca9ceb91e58c70183bb14e275b92b5
Diffstat (limited to 'libc/include')
-rw-r--r--libc/include/sys/select.h23
1 files changed, 11 insertions, 12 deletions
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index c8cd8e1..50ac228 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
+#include <string.h>
__BEGIN_DECLS
@@ -46,21 +47,19 @@ typedef struct {
#define __FDELT(fd) ((fd) / __NFDBITS)
#define __FDMASK(fd) (1UL << ((fd) % __NFDBITS))
#define __FDS_BITS(set) (((fd_set*)(set))->fds_bits)
+#define __FD_ZERO(set) (memset(set, 0, sizeof(*(fd_set*)(set))))
+
+#if defined(__BIONIC_FORTIFY)
+extern void __FD_CLR_chk(int, fd_set*, size_t);
+extern void __FD_SET_chk(int, fd_set*, size_t);
+extern int __FD_ISSET_chk(int, fd_set*, size_t);
+#define __FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
+#define __FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set))
+#define __FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
+#else
#define __FD_CLR(fd, set) (__FDS_BITS(set)[__FDELT(fd)] &= ~__FDMASK(fd))
#define __FD_SET(fd, set) (__FDS_BITS(set)[__FDELT(fd)] |= __FDMASK(fd))
#define __FD_ISSET(fd, set) ((__FDS_BITS(set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
-#define __FD_ZERO(set) (__builtin_memset(set, 0, sizeof(*(fd_set*)(set))))
-
-#if defined(__BIONIC_FORTIFY)
-extern void __FD_CLR_chk(int, fd_set*);
-extern void __FD_SET_chk(int, fd_set*);
-extern int __FD_ISSET_chk(int, fd_set*);
-#undef __FD_CLR
-#undef __FD_SET
-#undef __FD_ISSET
-#define __FD_CLR(fd, set) __FD_CLR_chk(fd, set)
-#define __FD_SET(fd, set) __FD_SET_chk(fd, set)
-#define __FD_ISSET(fd, set) __FD_ISSET_chk(fd, set)
#endif /* defined(__BIONIC_FORTIFY) */
extern int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);