Merge "libc: enable sprintf FORTIFY_SOURCE under clang"
This commit is contained in:
commit
0ea1d5c0ae
5 changed files with 58 additions and 2 deletions
|
@ -450,10 +450,11 @@ int vfdprintf(int, const char*, __va_list)
|
|||
__END_DECLS
|
||||
#endif /* _GNU_SOURCE */
|
||||
|
||||
#if defined(__BIONIC_FORTIFY) && !defined(__clang__)
|
||||
#if defined(__BIONIC_FORTIFY)
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#if !defined(__clang__)
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
__printflike(3, 0)
|
||||
int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
|
||||
|
@ -475,7 +476,11 @@ int snprintf(char *str, size_t size, const char *format, ...)
|
|||
return __builtin___snprintf_chk(str, size, 0,
|
||||
__bos(str), format, __builtin_va_arg_pack());
|
||||
}
|
||||
#endif /* !defined(__clang__) */
|
||||
|
||||
#if defined(__clang__)
|
||||
#define sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
|
||||
#else
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
__printflike(2, 3)
|
||||
int sprintf(char *dest, const char *format, ...)
|
||||
|
@ -483,7 +488,9 @@ int sprintf(char *dest, const char *format, ...)
|
|||
return __builtin___sprintf_chk(dest, 0,
|
||||
__bos(dest), format, __builtin_va_arg_pack());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(__clang__)
|
||||
extern char *__fgets_real(char *, int, FILE *)
|
||||
__asm__(__USER_LABEL_PREFIX__ "fgets");
|
||||
__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
|
||||
|
@ -521,8 +528,10 @@ char *fgets(char *dest, int size, FILE *stream)
|
|||
return __fgets_chk(dest, size, stream, bos);
|
||||
}
|
||||
|
||||
#endif /* !defined(__clang__) */
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* defined(__BIONIC_FORTIFY) && !defined(__clang__) */
|
||||
#endif /* defined(__BIONIC_FORTIFY) */
|
||||
|
||||
#endif /* _STDIO_H_ */
|
||||
|
|
|
@ -100,6 +100,12 @@ TEST(Fortify1_DeathTest, sprintf_fortified) {
|
|||
ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify1_DeathTest, sprintf2_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[5];
|
||||
ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify1_DeathTest, strncat_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[10];
|
||||
|
|
|
@ -92,6 +92,20 @@ TEST(Fortify1_Clang_DeathTest, strlcpy_fortified) {
|
|||
|
||||
#endif
|
||||
|
||||
TEST(Fortify1_Clang_DeathTest, sprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[10];
|
||||
char source_buf[15];
|
||||
memcpy(source_buf, "12345678901234", 15);
|
||||
ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify1_Clang_DeathTest, sprintf2_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[5];
|
||||
ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify1_Clang_DeathTest, strncat_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[10];
|
||||
|
|
|
@ -46,6 +46,13 @@ TEST(Fortify2_DeathTest, sprintf_fortified2) {
|
|||
testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_DeathTest, sprintf2_fortified2) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
foo myfoo;
|
||||
ASSERT_EXIT(sprintf(myfoo.a, "0123456789"),
|
||||
testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
#if __BIONIC__
|
||||
// zero sized target with "\0" source (should fail)
|
||||
TEST(Fortify2_DeathTest, strcpy_fortified2) {
|
||||
|
@ -229,6 +236,12 @@ TEST(Fortify2_DeathTest, sprintf_fortified) {
|
|||
ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_DeathTest, sprintf2_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[5];
|
||||
ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_DeathTest, strncat_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[10];
|
||||
|
|
|
@ -109,6 +109,20 @@ TEST(Fortify2_Clang_DeathTest, strrchr_fortified) {
|
|||
}
|
||||
#endif
|
||||
|
||||
TEST(Fortify2_Clang_DeathTest, sprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[10];
|
||||
char source_buf[15];
|
||||
memcpy(source_buf, "12345678901234", 15);
|
||||
ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_Clang_DeathTest, sprintf2_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[5];
|
||||
ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_Clang_DeathTest, strncat_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char buf[10];
|
||||
|
|
Loading…
Reference in a new issue