[PATCH] D35136: Use internal_strncpy to copy filename in linux procmaps

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 12:41:34 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL307696: Use internal_strncpy to copy filename in linux procmaps (authored by fjricci).

Repository:
  rL LLVM

https://reviews.llvm.org/D35136

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
@@ -62,13 +62,12 @@
   while (current_ < next_line && *current_ == ' ')
     current_++;
   // Fill in the filename.
-  uptr i = 0;
-  while (current_ < next_line) {
-    if (segment->filename && i < segment->filename_size - 1)
-      segment->filename[i++] = *current_;
-    current_++;
+  if (segment->filename) {
+    uptr len = Min((uptr)(next_line - current_), segment->filename_size - 1);
+    internal_strncpy(segment->filename, current_, len);
+    segment->filename[len] = 0;
   }
-  if (segment->filename && i < segment->filename_size) segment->filename[i] = 0;
+
   current_ = next_line + 1;
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35136.106082.patch
Type: text/x-patch
Size: 906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170711/c8b0e161/attachment.bin>


More information about the llvm-commits mailing list