Skip to content

Commit de6f725

Browse files
richlowerorth
authored andcommitted
[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
1 parent 60a085b commit de6f725

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
5555

5656
internal_snprintf(proc_path, sizeof(proc_path), "/proc/self/path/%s",
5757
xmapentry->pr_mapname);
58-
internal_readlink(proc_path, segment->filename, segment->filename_size);
58+
ssize_t sz = internal_readlink(proc_path, segment->filename,
59+
segment->filename_size - 1);
60+
61+
// If readlink failed, the map is anonymous.
62+
if (sz == -1) {
63+
segment->filename[0] = '\0';
64+
} else if ((size_t)sz < segment->filename_size)
65+
// readlink doesn't NUL-terminate.
66+
segment->filename[sz] = '\0';
5967
}
6068

6169
data_.current += sizeof(prxmap_t);

0 commit comments

Comments
 (0)