proc: fix capture of mapped pathnames

pathnames are listed unescaped in /proc/[pid]/maps, so using %s as the
conversion specifier cuts pathnames off at space characters. Use %[^\n]
instead, to read everything until the end of the line.

Also, the scanf manpage states: "String input conversions store a
terminating null byte ('\0') to mark the end of the input; the maximum
field width does not include this terminator". So set the maximum field
width to 511 instead of 512, to leave one free byte in the buffer for
the terminating null byte.

Fixes #70
This commit is contained in:
Florian Will
2021-11-23 13:54:48 +01:00
parent 2406d9209d
commit 03652e1a44

View File

@ -101,10 +101,14 @@ sysprof_proc_source_populate_maps (SysprofProcSource *self,
gint r;
r = sscanf (lines[i],
"%lx-%lx %*15s %lx %*x:%*x %lu %512s",
"%lx-%lx %*15s %lx %*x:%*x %lu %511[^\n]",
&start, &end, &offset, &inode, file);
file [sizeof file - 1] = '\0';
/* file has a " (deleted)" suffix if it was deleted from disk */
if (g_str_has_suffix (file, " (deleted)"))
file [strlen (file) - strlen (" (deleted)")] = '\0';
if (r != 5)
continue;