Merge "libc fortify: make poll.h and stat.h use diagnose_if" am: cff14d9e3e

am: f5b6f13394

Change-Id: I55e54e5aee89e9deb7c01f0f43fdfefe33217c45
This commit is contained in:
George Burgess IV 2017-08-02 06:55:53 +00:00 committed by android-build-merger
commit 910c9ec619
3 changed files with 22 additions and 39 deletions

View file

@ -37,42 +37,31 @@ int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*,
#if defined(__BIONIC_FORTIFY) #if defined(__BIONIC_FORTIFY)
#if __ANDROID_API__ >= __ANDROID_API_M__ #if __ANDROID_API__ >= __ANDROID_API_M__
#if defined(__clang__) #if defined(__clang__)
__BIONIC_ERROR_FUNCTION_VISIBILITY
int poll(struct pollfd* fds, nfds_t fd_count, int timeout) __overloadable
__enable_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&
__bos(fds) < sizeof(*fds) * fd_count,
"selected when there aren't fd_count fds")
__errorattr("too many fds specified");
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
int poll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, int poll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, int timeout)
int timeout) __overloadable { __overloadable
__clang_error_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&
__bos(fds) < sizeof(*fds) * fd_count,
"in call to 'poll', fd_count is larger than the given buffer") {
size_t bos_fds = __bos(fds); size_t bos_fds = __bos(fds);
if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) { if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
return __call_bypassing_fortify(poll)(fds, fd_count, timeout); return __call_bypassing_fortify(poll)(fds, fd_count, timeout);
} }
return __poll_chk(fds, fd_count, timeout, bos_fds); return __poll_chk(fds, fd_count, timeout, bos_fds);
} }
__BIONIC_ERROR_FUNCTION_VISIBILITY
int ppoll(struct pollfd* fds, nfds_t fd_count, const struct timespec* timeout,
const sigset_t* mask) __overloadable
__enable_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&
__bos(fds) < sizeof(*fds) * fd_count,
"selected when there aren't fd_count fds")
__errorattr("too many fds specified");
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, const struct timespec* timeout, const sigset_t* mask)
const struct timespec* timeout, const sigset_t* mask) __overloadable { __overloadable
__clang_error_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&
__bos(fds) < sizeof(*fds) * fd_count,
"in call to 'ppoll', fd_count is larger than the given buffer") {
size_t bos_fds = __bos(fds); size_t bos_fds = __bos(fds);
if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) { if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
return __call_bypassing_fortify(ppoll)(fds, fd_count, timeout, mask); return __call_bypassing_fortify(ppoll)(fds, fd_count, timeout, mask);
} }
return __ppoll_chk(fds, fd_count, timeout, mask, bos_fds); return __ppoll_chk(fds, fd_count, timeout, mask, bos_fds);
} }
#else /* defined(__clang__) */ #else /* defined(__clang__) */

View file

@ -33,23 +33,17 @@
mode_t __umask_chk(mode_t) __INTRODUCED_IN(18); mode_t __umask_chk(mode_t) __INTRODUCED_IN(18);
#if defined(__BIONIC_FORTIFY) #if defined(__BIONIC_FORTIFY)
#define __umask_invalid_mode_str "umask called with invalid mode" #define __umask_invalid_mode_str "'umask' called with invalid mode"
#if defined(__clang__) #if defined(__clang__)
#if __ANDROID_API__ >= __ANDROID_API_J_MR2__ #if __ANDROID_API__ >= __ANDROID_API_J_MR2__
/* /* Abuse enable_if to make this an overload of umask. */
* Abuse enable_if to make these be seen as overloads of umask, rather than
* definitions.
*/
__BIONIC_ERROR_FUNCTION_VISIBILITY
mode_t umask(mode_t mode) __overloadable
__enable_if(1, "")
__enable_if(mode & ~0777, __umask_invalid_mode_str)
__errorattr(__umask_invalid_mode_str);
__BIONIC_FORTIFY_INLINE __BIONIC_FORTIFY_INLINE
mode_t umask(mode_t mode) __enable_if(1, "") __overloadable { mode_t umask(mode_t mode)
__overloadable
__enable_if(1, "")
__clang_error_if(mode & ~0777, __umask_invalid_mode_str) {
return __umask_chk(mode); return __umask_chk(mode);
} }
#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */

View file

@ -190,8 +190,8 @@ void test_recvfrom() {
void test_umask() { void test_umask() {
// NOLINTNEXTLINE(whitespace/line_length) // NOLINTNEXTLINE(whitespace/line_length)
// GCC: error: call to '__umask_invalid_mode' declared with attribute error: umask called with invalid mode // GCC: error: call to '__umask_invalid_mode' declared with attribute error: 'umask' called with invalid mode
// CLANG: error: call to unavailable function 'umask': umask called with invalid mode // CLANG: error: 'umask' called with invalid mode
umask(01777); umask(01777);
} }
@ -219,7 +219,7 @@ void test_poll() {
pollfd fds[1]; pollfd fds[1];
// NOLINTNEXTLINE(whitespace/line_length) // NOLINTNEXTLINE(whitespace/line_length)
// GCC: error: call to '__poll_too_small_error' declared with attribute error: poll: pollfd array smaller than fd count // GCC: error: call to '__poll_too_small_error' declared with attribute error: poll: pollfd array smaller than fd count
// CLANG: error: call to unavailable function 'poll': too many fds specified // CLANG: error: in call to 'poll', fd_count is larger than the given buffer
poll(fds, 2, 0); poll(fds, 2, 0);
} }
@ -228,7 +228,7 @@ void test_ppoll() {
timespec timeout; timespec timeout;
// NOLINTNEXTLINE(whitespace/line_length) // NOLINTNEXTLINE(whitespace/line_length)
// GCC: error: call to '__ppoll_too_small_error' declared with attribute error: ppoll: pollfd array smaller than fd count // GCC: error: call to '__ppoll_too_small_error' declared with attribute error: ppoll: pollfd array smaller than fd count
// CLANG: error: call to unavailable function 'ppoll': too many fds specified // CLANG: error: in call to 'ppoll', fd_count is larger than the given buffer
ppoll(fds, 2, &timeout, NULL); ppoll(fds, 2, &timeout, NULL);
} }