[PATCH] D48250: [sanitizer_common] Use O_TRUNC for WrOnly access mode.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 15 16:24:17 PDT 2018


MaskRay created this revision.
MaskRay added reviewers: glider, timurrrr.
Herald added subscribers: Sanitizers, llvm-commits, delcypher, kubamracek.

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.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D48250

Files:
  lib/sanitizer_common/sanitizer_posix.cc


Index: lib/sanitizer_common/sanitizer_posix.cc
===================================================================
--- lib/sanitizer_common/sanitizer_posix.cc
+++ lib/sanitizer_common/sanitizer_posix.cc
@@ -160,7 +160,7 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48250.151585.patch
Type: text/x-patch
Size: 521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180615/0776b899/attachment.bin>


More information about the llvm-commits mailing list