summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-02-05 15:00:13 -0800
committerElliott Hughes <enh@google.com>2019-02-05 15:00:13 -0800
commit288465d6e908a4a2b9f8ed27834fc5861bae0ed3 (patch)
tree60ed2b0f19354c21223fd8539c68a32568fe3c42 /tests/stdio_test.cpp
parent5c45c4efb28f103112ed8765386184d802afea73 (diff)
Avoid writing to a zero-capacity buffer.
Bug: http://b/120752721 Test: ran tests Change-Id: I3f03ae204ab5de40fd4402a5562c50ffe51ef998
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 479fd9d62..ad6ed45a9 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1820,6 +1820,14 @@ TEST(STDIO_TEST, fmemopen_zero_length) {
ASSERT_EQ(0, fclose(fp));
}
+TEST(STDIO_TEST, fmemopen_zero_length_buffer_overrun) {
+ char buf[2] = "x";
+ ASSERT_EQ('x', buf[0]);
+ FILE* fp = fmemopen(buf, 0, "w");
+ ASSERT_EQ('x', buf[0]);
+ ASSERT_EQ(0, fclose(fp));
+}
+
TEST(STDIO_TEST, fmemopen_write_only_allocated) {
// POSIX says fmemopen "may fail if the mode argument does not include a '+'".
// BSD fails, glibc doesn't. We side with the more lenient.