X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=util%2Fstring-util.c;h=b0108811903b27153dcaece1fa10b893234c3b9f;hb=HEAD;hp=27f8a26b4938c4c770486e504b62f168db64f582;hpb=3fb123f215668a54cd6084b2a520f767d2be6712;p=notmuch diff --git a/util/string-util.c b/util/string-util.c index 27f8a26b..03d7648d 100644 --- a/util/string-util.c +++ b/util/string-util.c @@ -42,21 +42,23 @@ const char * strsplit_len (const char *s, char delim, size_t *len) { bool escaping = false; - size_t count = 0; + size_t count = 0, last_nonspace = 0; - /* Skip initial unescaped delimiters */ - while (*s && *s == delim) + /* Skip initial unescaped delimiters and whitespace */ + while (*s && (*s == delim || isspace (*s))) s++; while (s[count] && (escaping || s[count] != delim)) { + if (! isspace (s[count])) + last_nonspace = count; escaping = (s[count] == '\\'); count++; } - if (count==0) + if (count == 0) return NULL; - *len = count; + *len = last_nonspace + 1; return s; } @@ -183,6 +185,7 @@ parse_boolean_term (void *ctx, const char *str, /* Parse prefix */ str = skip_space (str); const char *pos = strchr (str, ':'); + if (! pos || pos == str) goto FAIL; *prefix_out = talloc_strndup (ctx, str, pos - str);