summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/tests
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-06-16 03:32:59 +0000
committerFangrui Song <maskray@google.com>2018-06-16 03:32:59 +0000
commitd40fc6019b26f2b64a80fc5fcb2de73e50ba838e (patch)
treefa87a3aa8db310f6f21b0cd14fe6ba3b55878d1d /compiler-rt/lib/sanitizer_common/tests
parentd4ff2f8a743681583ec6426b4ad488151fa1b9dc (diff)
downloadbcm5719-llvm-d40fc6019b26f2b64a80fc5fcb2de73e50ba838e.tar.gz
bcm5719-llvm-d40fc6019b26f2b64a80fc5fcb2de73e50ba838e.zip
[sanitizer_common] Use O_TRUNC for WrOnly access mode.
Summary: Otherwise if the file existed and was larger than the write size before the OpenFile call, the file will not be truncated and contain garbage in trailing bytes. Reviewers: glider, kcc, vitalybuka Subscribers: kubamracek, delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D48250 llvm-svn: 334881
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/tests')
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc
index 3e9c5c59e43..5285cb01b02 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc
@@ -108,6 +108,12 @@ TEST(SanitizerCommon, FileOps) {
temp_file_name(tmpfile, sizeof(tmpfile), "sanitizer_common.fileops.tmp.");
fd_t fd = OpenFile(tmpfile, WrOnly);
ASSERT_NE(fd, kInvalidFd);
+ ASSERT_FALSE(internal_iserror(internal_write(fd, "A", 1)));
+ CloseFile(fd);
+
+ fd = OpenFile(tmpfile, WrOnly);
+ ASSERT_NE(fd, kInvalidFd);
+ EXPECT_EQ(internal_lseek(fd, 0, SEEK_END), 0u);
uptr bytes_written = 0;
EXPECT_TRUE(WriteToFile(fd, str1, len1, &bytes_written));
EXPECT_EQ(len1, bytes_written);
OpenPOWER on IntegriCloud