diff options
| author | Fangrui Song <maskray@google.com> | 2018-06-16 03:32:59 +0000 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2018-06-16 03:32:59 +0000 |
| commit | d40fc6019b26f2b64a80fc5fcb2de73e50ba838e (patch) | |
| tree | fa87a3aa8db310f6f21b0cd14fe6ba3b55878d1d /compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | |
| parent | d4ff2f8a743681583ec6426b4ad488151fa1b9dc (diff) | |
| download | bcm5719-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/sanitizer_posix.cc')
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index ad0b4d0ea0b..f7dfc86f58c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -160,7 +160,7 @@ fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p) { int flags; switch (mode) { case RdOnly: flags = O_RDONLY; break; - case WrOnly: flags = O_WRONLY | O_CREAT; break; + case WrOnly: flags = O_WRONLY | O_CREAT | O_TRUNC; break; case RdWr: flags = O_RDWR | O_CREAT; break; } fd_t res = internal_open(filename, flags, 0660); |

