summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-12 15:15:37 -0700
committerElliott Hughes <enh@google.com>2014-05-12 15:15:37 -0700
commit20f8aec8976b17ad4d9da6be265594d924f368e1 (patch)
tree47ba26f39bdd496b60027c5f63229236ec4bc1a6 /tests/stdio_test.cpp
parentebcc72070499b2ab2d1dee990d6f52814a56600e (diff)
Fix use-after-free errors in stdio_test.
fclose(3) frees the passed-in FILE*. We should close(2) the underlying fd, not fclose(3) the stream, if we want to test what happens with a stream we can't read from. Bug: 14466691 Change-Id: I99fed5904b0266b9c6ae05d0b9cf2e926446c064
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 73e9dcdf7..8f6ee2b0e 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -102,14 +102,12 @@ TEST(stdio, getdelim_invalid) {
ASSERT_EQ(getdelim(&buffer, NULL, ' ', fp), -1);
ASSERT_EQ(EINVAL, errno);
- // The stream can't be closed.
- fclose(fp);
+ // The underlying fd can't be closed.
+ ASSERT_EQ(0, close(fileno(fp)));
errno = 0;
ASSERT_EQ(getdelim(&buffer, &buffer_length, ' ', fp), -1);
- // glibc sometimes doesn't set errno in this particular case.
-#if defined(__BIONIC__)
ASSERT_EQ(EBADF, errno);
-#endif // __BIONIC__
+ fclose(fp);
}
TEST(stdio, getline) {
@@ -171,14 +169,12 @@ TEST(stdio, getline_invalid) {
ASSERT_EQ(getline(&buffer, NULL, fp), -1);
ASSERT_EQ(EINVAL, errno);
- // The stream can't be closed.
- fclose(fp);
+ // The underlying fd can't be closed.
+ ASSERT_EQ(0, close(fileno(fp)));
errno = 0;
ASSERT_EQ(getline(&buffer, &buffer_length, fp), -1);
- // glibc sometimes doesn't set errno in this particular case.
-#if defined(__BIONIC__)
ASSERT_EQ(EBADF, errno);
-#endif // __BIONIC__
+ fclose(fp);
}
TEST(stdio, printf_ssize_t) {