diff options
author | Elliott Hughes <enh@google.com> | 2016-08-10 11:07:54 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-08-10 11:50:12 -0700 |
commit | fb3873d4db3012ac2d1ba87d688138798787c6e0 (patch) | |
tree | 1e392110ebe5ca3b0f3f466e493c1085b403b864 /tests/stdio_test.cpp | |
parent | f5042cab109f7136191fd316be1471532d2ddf71 (diff) | |
download | android_bionic-fb3873d4db3012ac2d1ba87d688138798787c6e0.tar.gz android_bionic-fb3873d4db3012ac2d1ba87d688138798787c6e0.tar.bz2 android_bionic-fb3873d4db3012ac2d1ba87d688138798787c6e0.zip |
Fortify vsnprintf in more cases.
Bug: http://b/30445072
Change-Id: I1893890f0e3b56533eef053eda1bd96a0b9a5119
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r-- | tests/stdio_test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 8747dfc6d..ecba4ad3b 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -29,14 +29,20 @@ #include <vector> +#include "BionicDeathTest.h" #include "TemporaryFile.h" #if defined(NOFORTIFY) #define STDIO_TEST stdio_nofortify +#define STDIO_DEATHTEST stdio_nofortify_DeathTest #else #define STDIO_TEST stdio +#define STDIO_DEATHTEST stdio_DeathTest #endif +class stdio_DeathTest : public BionicDeathTest {}; +class stdio_nofortify_DeathTest : public BionicDeathTest {}; + static void AssertFileIs(FILE* fp, const char* expected, bool is_fmemopen = false) { rewind(fp); @@ -1329,3 +1335,28 @@ TEST(STDIO_TEST, remove) { ASSERT_EQ(-1, remove(td.dirname)); ASSERT_EQ(ENOENT, errno); } + +TEST(STDIO_DEATHTEST, snprintf_30445072_known_buffer_size) { + char buf[16]; + ASSERT_EXIT(snprintf(buf, atol("-1"), "hello"), + testing::KilledBySignal(SIGABRT), +#if defined(NOFORTIFY) + "FORTIFY: vsnprintf: size .* > SSIZE_MAX" +#else + "FORTIFY: vsnprintf: prevented .*-byte write into 16-byte buffer" +#endif + ); +} + +TEST(STDIO_DEATHTEST, snprintf_30445072_unknown_buffer_size) { + std::string buf = "world"; + ASSERT_EXIT(snprintf(&buf[0], atol("-1"), "hello"), + testing::KilledBySignal(SIGABRT), + "FORTIFY: vsnprintf: size .* > SSIZE_MAX"); +} + +TEST(STDIO_TEST, sprintf_30445072) { + std::string buf = "world"; + sprintf(&buf[0], "hello"); + ASSERT_EQ(buf, "hello"); +} |