[compiler-rt] de6f725 - [sanitizer_common] Fix readlink error handling in sanitizer_procmaps_solaris.cpp

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 2 14:06:43 PDT 2021


Author: Rich Lowe
Date: 2021-11-02T22:06:17+01:00
New Revision: de6f7252daf5da7fffa504a4c0106f377dbe76a0

URL: https://github.com/llvm/llvm-project/commit/de6f7252daf5da7fffa504a4c0106f377dbe76a0
DIFF: https://github.com/llvm/llvm-project/commit/de6f7252daf5da7fffa504a4c0106f377dbe76a0.diff

LOG: [sanitizer_common] Fix readlink error handling in sanitizer_procmaps_solaris.cpp

As pointed out in Bug 52371, the Solaris version of
`MemoryMappingLayout::Next` completely failed to handle `readlink` errors
or properly NUL-terminate the result.

This patch fixes this.  Originally provided in the PR with slight
formatting changes.

Tested on `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D112998

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
index bf813f235bb7..e16c4e938cb2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
@@ -55,7 +55,15 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
 
     internal_snprintf(proc_path, sizeof(proc_path), "/proc/self/path/%s",
                       xmapentry->pr_mapname);
-    internal_readlink(proc_path, segment->filename, segment->filename_size);
+    ssize_t sz = internal_readlink(proc_path, segment->filename,
+                                   segment->filename_size - 1);
+
+    // If readlink failed, the map is anonymous.
+    if (sz == -1) {
+      segment->filename[0] = '\0';
+    } else if ((size_t)sz < segment->filename_size)
+      // readlink doesn't NUL-terminate.
+      segment->filename[sz] = '\0';
   }
 
   data_.current += sizeof(prxmap_t);


        


More information about the llvm-commits mailing list