From 03652e1a441bb84653ee9eaa20791c2e05f8c787 Mon Sep 17 00:00:00 2001 From: Florian Will Date: Tue, 23 Nov 2021 13:54:48 +0100 Subject: [PATCH] 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 --- src/libsysprof/sysprof-proc-source.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libsysprof/sysprof-proc-source.c b/src/libsysprof/sysprof-proc-source.c index 2a9b8c61..b59d1d58 100644 --- a/src/libsysprof/sysprof-proc-source.c +++ b/src/libsysprof/sysprof-proc-source.c @@ -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;