aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2018-04-13 13:52:10 -0700
committerAndreas Gampe <agampe@google.com>2018-04-16 11:06:27 -0700
commit9302cf252687b8705570b794a901959efc0c26af (patch)
treeb333a0814a6b9e3b29edbf6c73a8ed80d5a32e95
parent5a0fe3e8bff96c465d00823f07ce36caac1b104d (diff)
downloadbionic-9302cf252687b8705570b794a901959efc0c26af.tar.gz
Bionic: Always use fortified versions of FD_X macros
When compiling on/for at least Lollipop, always use the fortified versions of FD_X macros. This works around side-effect issues (which are explicitly called out in the specification) and generally increases robustness of code. (cherry picked from commit 00a6d5fe0ab034e4d5e87636456cd49ef0ca5b8d) Bug: 77986327 Test: mmma bionic Test: m Test: bionic_unit_tests Merged-In: I9096c6872770e46ba5ab64e7375ff83fc0518e07 Change-Id: I9096c6872770e46ba5ab64e7375ff83fc0518e07
-rw-r--r--libc/bionic/fortify.cpp6
-rw-r--r--libc/include/sys/cdefs.h12
-rw-r--r--libc/include/sys/select.h15
3 files changed, 23 insertions, 10 deletions
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 985d47f08..c1340cb96 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -80,17 +80,17 @@
int __FD_ISSET_chk(int fd, const fd_set* set, size_t set_size) {
__check_fd_set("FD_ISSET", fd, set_size);
- return FD_ISSET(fd, set);
+ return __FD_ISSET(fd, set);
}
void __FD_CLR_chk(int fd, fd_set* set, size_t set_size) {
__check_fd_set("FD_CLR", fd, set_size);
- FD_CLR(fd, set);
+ __FD_CLR(fd, set);
}
void __FD_SET_chk(int fd, fd_set* set, size_t set_size) {
__check_fd_set("FD_SET", fd, set_size);
- FD_SET(fd, set);
+ __FD_SET(fd, set);
}
char* __fgets_chk(char* dst, int supplied_size, FILE* stream, size_t dst_len_from_compiler) {
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index c270bb513..c1913f0fc 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -289,14 +289,22 @@
# endif
#endif
+// As we move some FORTIFY checks to be always on, __bos needs to be
+// always available.
#if defined(__BIONIC_FORTIFY)
# if _FORTIFY_SOURCE == 2
# define __bos_level 1
# else
# define __bos_level 0
# endif
-# define __bosn(s, n) __builtin_object_size((s), (n))
-# define __bos(s) __bosn((s), __bos_level)
+#else
+# define __bos_level 0
+#endif
+
+#define __bosn(s, n) __builtin_object_size((s), (n))
+#define __bos(s) __bosn((s), __bos_level)
+
+#if defined(__BIONIC_FORTIFY)
# define __bos0(s) __bosn((s), 0)
# if defined(__clang__)
# define __pass_object_size_n(n) __attribute__((pass_object_size(n)))
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index 603a5a676..e58df219e 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -63,15 +63,20 @@ void __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21);
-#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= __ANDROID_API_L__
+#define __FD_CLR(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] &= ~__FDMASK(fd))
+#define __FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
+#define __FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
+
+
+#if __ANDROID_API__ >= __ANDROID_API_L__
#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(fd_set*,set)[__FDELT(fd)] &= ~__FDMASK(fd))
-#define FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
-#define FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
-#endif /* defined(__BIONIC_FORTIFY) && __ANDROID_API >= 21 */
+#define FD_CLR(fd, set) __FD_CLR(fd, set)
+#define FD_SET(fd, set) __FD_SET(fd, set)
+#define FD_ISSET(fd, set) __FD_ISSET(fd, set)
+#endif /* __ANDROID_API >= 21 */
int select(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, struct timeval* __timeout);
int pselect(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset_t* __mask);