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");
#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
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;
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;