From aa1a94db531e3704e3f1f9ba74f182c514e2a5ee Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 5 Apr 2018 19:22:08 +0000 Subject: [PATCH] Skip whole quoted program name when parsing args with --resume --- nmap.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/nmap.cc b/nmap.cc index 2b3cf8ff5..117d3d8fb 100644 --- a/nmap.cc +++ b/nmap.cc @@ -2297,8 +2297,30 @@ int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) { p += 5; else fatal("Unable to parse supposed log file %s. Are you sure this is an Nmap output file?", fname); - while (*p && !isspace((int) (unsigned char) *p)) + /* Skip the program name */ + while (*p && !isspace((int) (unsigned char) *p)){ + if (*p == '"' || *p == '\'') { + /* Quoted, so find the matching quote. + * TODO:Doesn't handle escaped quotes, but we don't generate them either. */ + p = strchr(p+1, *p); + if (!p) { + fatal("Unable to parse supposed log file %s: unclosed quote.", fname); + } + } + else if (!strncasecmp(p, """, 6)) { + /* We do XML unescaping later, but this is just special case of quoted + * program name. */ + do { + p = strstr(p+1, "&"); + if (!p) { + fatal("Unable to parse supposed log file %s: unclosed quote.", fname); + } + } while (strncasecmp(p, """, 6)); + /* Only skip to the ';', because another increment happens below. */ + p += 5; + } p++; + } if (!*p) fatal("Unable to parse supposed log file %s. Sorry", fname); p++; /* Skip the space between program name and first arg */