From: Mateusz Moscicki Date: Mon, 15 Oct 2018 11:43:15 +0000 (+0200) Subject: Handle spaces in the crashed app pathname and in the maps file X-Git-Tag: submit/tizen/20181031.134751~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d23978584db9f97fa516c1c64a7bd355962a0467;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git Handle spaces in the crashed app pathname and in the maps file Change-Id: I98ff537cab9c37b78dc3f3056a375fd10461b7ea --- diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 686a13e..a02d59c 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -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"); diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index bf1cd38..61b876c 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -62,6 +62,11 @@ #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; diff --git a/src/crash-stack/unwind.c b/src/crash-stack/unwind.c index bce9ef8..d372bbe 100644 --- a/src/crash-stack/unwind.c +++ b/src/crash-stack/unwind.c @@ -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;