aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2016-10-25 13:41:10 +0200
committerKarel Zak <kzak@redhat.com>2016-10-25 13:42:48 +0200
commit8430b9b88426eb3c273b02a2d9505d839913317c (patch)
tree71411e2e41f430af949fc5abe417395c8698266d
parent0dcfebf527744bf9b78c576a64ddec7d4367afe3 (diff)
downloadutil-linux-8430b9b88426eb3c273b02a2d9505d839913317c.tar.gz
libfdisk: make script token parser more robust
* make sure token is terminated * skip closing quotes * allow extra space after quotes and before terminater * skip extra space after terminater Addresses: https://github.com/karelzak/util-linux/issues/367 Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libfdisk/src/script.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c
index 4c1f9c7b96..54621ae289 100644
--- a/libfdisk/src/script.c
+++ b/libfdisk/src/script.c
@@ -736,7 +736,7 @@ static char *next_token(char **str)
*tk_end = NULL,
*end = NULL,
*p;
- int open_quote = 0;
+ int open_quote = 0, terminated = 0;
for (p = *str; p && *p; p++) {
if (!tk_begin) {
@@ -758,9 +758,35 @@ static char *next_token(char **str)
if (!tk_end)
return NULL;
- end = isblank(*tk_end) ? (char *) skip_blank(tk_end) : tk_end;
- if (*end == ',' || *end == ';')
+
+ end = tk_end;
+
+ /* skip closing quotes */
+ if (*end == '"')
+ end++;
+
+ /* token is terminated by blank (or blank is before "," or ";") */
+ if (isblank(*end)) {
+ end = (char *) skip_blank(end);
+ terminated++;
+ }
+
+ /* token is terminated by "," or ";" */
+ if (*end == ',' || *end == ';') {
end++;
+ terminated++;
+
+ /* token is terminated by \0 */
+ } else if (!*end)
+ terminated++;
+
+ if (!terminated) {
+ DBG(SCRIPT, ul_debug("unterminated token '%s'", end));
+ return NULL;
+ }
+
+ /* skip extra space after terminator */
+ end = (char *) skip_blank(end);
*tk_end = '\0';
*str = end;