[llvm-commits] [compiler-rt] r148311 - /compiler-rt/trunk/lib/asan/asan_rtl.cc

Kostya Serebryany kcc at google.com
Tue Jan 17 10:00:07 PST 2012


Author: kcc
Date: Tue Jan 17 12:00:07 2012
New Revision: 148311

URL: http://llvm.org/viewvc/llvm-project?rev=148311&view=rev
Log:
[asan] fix ReadFileToBuffer to correctly handle files from /proc/ (asan issue 27)

Modified:
    compiler-rt/trunk/lib/asan/asan_rtl.cc

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=148311&r1=148310&r2=148311&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Jan 17 12:00:07 2012
@@ -16,7 +16,6 @@
 #include "asan_interface.h"
 #include "asan_internal.h"
 #include "asan_lock.h"
-#include "asan_mac.h"
 #include "asan_mapping.h"
 #include "asan_procmaps.h"
 #include "asan_stack.h"
@@ -83,9 +82,19 @@
     AsanUnmapOrDie(*buff, *buff_size);
     *buff = (char*)AsanMmapSomewhereOrDie(size, __FUNCTION__);
     *buff_size = size;
-    read_len = AsanRead(fd, *buff, size);
+    // Read up to one page at a time.
+    read_len = 0;
+    bool reached_eof = false;
+    while (read_len + kPageSize <= size) {
+      size_t just_read = AsanRead(fd, *buff + read_len, kPageSize);
+      if (just_read == 0) {
+        reached_eof = true;
+        break;
+      }
+      read_len += just_read;
+    }
     AsanClose(fd);
-    if (read_len < size)  // We've read the whole file.
+    if (reached_eof)  // We've read the whole file.
       break;
   }
   return read_len;





More information about the llvm-commits mailing list