forked from OSchip/llvm-project
[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
This commit is contained in:
parent
60a085beb0
commit
de6f7252da
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue