am 71802135: am bfacb603: Merge "libc: enable FORTIFY_SOURCE snprintf under clang"
* commit '7180213557f3120b391053b4f5861037eda6ebb6': libc: enable FORTIFY_SOURCE snprintf under clang
This commit is contained in:
commit
caad18c7d1
@ -468,15 +468,19 @@ int vsprintf(char *dest, const char *format, __va_list ap)
|
||||
{
|
||||
return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
|
||||
}
|
||||
#endif /* !defined(__clang__) */
|
||||
|
||||
#if defined(__clang__)
|
||||
#define snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
|
||||
#else
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
__printflike(3, 4)
|
||||
int snprintf(char *str, size_t size, const char *format, ...)
|
||||
int snprintf(char *dest, size_t size, const char *format, ...)
|
||||
{
|
||||
return __builtin___snprintf_chk(str, size, 0,
|
||||
__bos(str), format, __builtin_va_arg_pack());
|
||||
return __builtin___snprintf_chk(dest, size, 0,
|
||||
__bos(dest), format, __builtin_va_arg_pack());
|
||||
}
|
||||
#endif /* !defined(__clang__) */
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
#define sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
|
||||
|
@ -157,6 +157,15 @@ TEST(Fortify1_DeathTest, strncpy_fortified) {
|
||||
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify1_DeathTest, snprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char bufa[15];
|
||||
char bufb[10];
|
||||
strcpy(bufa, "0123456789");
|
||||
size_t n = strlen(bufa) + 1;
|
||||
ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
extern "C" char* __strncat_chk(char*, const char*, size_t, size_t);
|
||||
extern "C" char* __strcat_chk(char*, const char*, size_t);
|
||||
|
||||
|
@ -157,6 +157,15 @@ TEST(Fortify1_Clang_DeathTest, strncpy_fortified) {
|
||||
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify1_Clang_DeathTest, snprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char bufa[15];
|
||||
char bufb[10];
|
||||
strcpy(bufa, "0123456789");
|
||||
size_t n = strlen(bufa) + 1;
|
||||
ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
extern "C" char* __strncat_chk(char*, const char*, size_t, size_t);
|
||||
extern "C" char* __strcat_chk(char*, const char*, size_t);
|
||||
|
||||
|
@ -155,6 +155,14 @@ TEST(Fortify2_DeathTest, strcat2_fortified2) {
|
||||
ASSERT_EXIT(strcat(myfoo.b, myfoo.a), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_DeathTest, snprintf_fortified2) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
foo myfoo;
|
||||
strcpy(myfoo.a, "012345678");
|
||||
size_t n = strlen(myfoo.a) + 2;
|
||||
ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
/* TESTS BELOW HERE DUPLICATE TESTS FROM fortify1_test.cpp */
|
||||
/***********************************************************/
|
||||
@ -292,3 +300,12 @@ TEST(Fortify2_DeathTest, strncpy_fortified) {
|
||||
size_t n = strlen(bufa);
|
||||
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_DeathTest, snprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char bufa[15];
|
||||
char bufb[10];
|
||||
strcpy(bufa, "0123456789");
|
||||
size_t n = strlen(bufa) + 1;
|
||||
ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
@ -174,6 +174,15 @@ TEST(Fortify2_Clang_DeathTest, strncpy_fortified) {
|
||||
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(Fortify2_Clang_DeathTest, snprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char bufa[15];
|
||||
char bufb[10];
|
||||
strcpy(bufa, "0123456789");
|
||||
size_t n = strlen(bufa) + 1;
|
||||
ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
size_t test_fortify2_inline(char* buf) {
|
||||
return __bos(buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user