Handle spaces in the crashed app pathname and in the maps file 59/191359/5
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Mon, 15 Oct 2018 11:43:15 +0000 (13:43 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 24 Oct 2018 13:32:24 +0000 (15:32 +0200)
Change-Id: I98ff537cab9c37b78dc3f3056a375fd10461b7ea

src/crash-manager/crash-manager.c
src/crash-stack/crash-stack.c
src/crash-stack/unwind.c

index 686a13e..a02d59c 100644 (file)
@@ -692,7 +692,7 @@ static int dump_system_state(const struct crash_info *cinfo)
        char command[PATH_MAX];
 
        ret = snprintf(command, sizeof(command),
-                       "/usr/bin/dump_systemstate -d -k -j -f %s",
+                       "/usr/bin/dump_systemstate -d -k -j -f '%s'",
                        cinfo->log_path);
        if (ret < 0) {
                _E("Failed to snprintf for dump_systemstate command");
index bf1cd38..61b876c 100644 (file)
 #define STRING_FORMAT_SPECIFIER_WITH_MACRO(macro) "%"#macro"s"
 #define STR_FS(macro) STRING_FORMAT_SPECIFIER_WITH_MACRO(macro)
 
+// this macro returns the format specifier to capture a string that can
+// contain spaces
+#define STRINGWW_FORMAT_SPECIFIER_WITH_MACRO(macro) "%"#macro"[^\t\n]"
+#define STRWW_FS(macro) STRINGWW_FORMAT_SPECIFIER_WITH_MACRO(macro)
+
 static FILE *outputfile = NULL;                ///< global output stream
 static FILE *errfile = NULL;           ///< global error stream
 static FILE *bufferfile = NULL;                ///< buffer file for ordering
@@ -377,7 +382,7 @@ static struct addr_node *get_addr_list_from_maps(int fd)
                result = sscanf(linebuf, STR_FS(ADDR_LEN)
                                 STR_FS(PERM_LEN)
                                 "%*s %*s %*s"
-                                STR_FS(PATH_MAX), addr, perm, path);
+                                STRWW_FS(PATH_MAX), addr, perm, path);
                if (result < 0)
                        continue;
                perm[PERM_LEN] = 0;
index bce9ef8..d372bbe 100644 (file)
@@ -861,7 +861,13 @@ void *_TB_create (pid_t pid) {
        if (fgets(buf, STAT_LINE_MAXSIZE, f) == NULL)
                goto out_err;
 
-       for (i = 0, p = buf; i < 28; i++) {
+       // The filename of the executable (the second field) is in parentheses and can
+       // contain whitespaces. Therefore I'm looking for the last ')' character
+       // and then iterate to the 27 field from here.
+       p = strrchr(buf, ')');
+       if (!p)
+               goto out_err;
+       for (i = 0; i < 27; i++) {
                p = strchr(p, ' ');
                if (!p)
                        goto out_err;