[PATCH] D112998: [sanitizer_common] Fix readlink error handling in sanitizer_procmaps_solaris.cpp
Rainer Orth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 2 03:33:34 PDT 2021
ro created this revision.
ro added a reviewer: vitalybuka.
ro added a project: Sanitizers.
Herald added a subscriber: fedor.sergeev.
ro requested review of this revision.
Herald added a subscriber: Sanitizers.
As Rich Lowe 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`.
I'm uncertain how to properly attribute the patch on commit, though.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112998
Files:
compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
Index: compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
@@ -55,7 +55,15 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112998.384027.patch
Type: text/x-patch
Size: 913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/f605e6a1/attachment.bin>
More information about the llvm-commits
mailing list