Merge "libc fortify: error on realpath(NULL, foo)"

am: 6beab08440

Change-Id: I50cf25955d28df10661e08579fac001f7abdab5f
This commit is contained in:
George Burgess IV 2017-08-15 17:45:01 +00:00 committed by android-build-merger
commit 87fcfefe26
3 changed files with 8 additions and 4 deletions

View file

@ -40,7 +40,8 @@
#if defined(__clang__) #if defined(__clang__)
char* realpath(const char* path, char* resolved) char* realpath(const char* path, char* resolved)
__clang_error_if(__bos(resolved) != __BIONIC_FORTIFY_UNKNOWN_SIZE && __clang_error_if(__bos(resolved) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&
__bos(resolved) < __PATH_MAX, __realpath_buf_too_small_str); __bos(resolved) < __PATH_MAX, __realpath_buf_too_small_str)
__clang_error_if(!path, "'realpath': NULL path is never correct; flipped arguments?");
/* No need for a definition; the only issues we can catch are at compile-time. */ /* No need for a definition; the only issues we can catch are at compile-time. */
#else /* defined(__clang__) */ #else /* defined(__clang__) */

View file

@ -376,6 +376,7 @@ void test_realpath() {
// This is fine. // This is fine.
realpath(".", NULL); realpath(".", NULL);
// FIXME: But we should warn on this. char bigbuf[PATH_MAX];
realpath(NULL, buf); // CLANG: error: 'realpath': NULL path is never correct; flipped arguments?
realpath(NULL, bigbuf);
} }

View file

@ -184,7 +184,9 @@ TEST(stdlib, posix_memalign_overflow) {
TEST(stdlib, realpath__NULL_filename) { TEST(stdlib, realpath__NULL_filename) {
errno = 0; errno = 0;
char* p = realpath(NULL, NULL); // Work around the compile-time error generated by FORTIFY here.
const char* path = NULL;
char* p = realpath(path, NULL);
ASSERT_TRUE(p == NULL); ASSERT_TRUE(p == NULL);
ASSERT_EQ(EINVAL, errno); ASSERT_EQ(EINVAL, errno);
} }