From a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 29 Jul 2014 22:01:36 -0400 Subject: Reject invalid quoted strings String which ended in an unfinished quote were accepted, potentially with bad memory accesses. Reject anything which ends in a unfished quote, or contains non-whitespace characters right after the closing quote. _FOREACH_WORD now returns the invalid character in *state. But this return value is not checked anywhere yet. Also, make 'word' and 'state' variables const pointers, and rename 'w' to 'word' in various places. Things are easier to read if the same name is used consistently. mbiebl_> am I correct that something like this doesn't work mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"' mbiebl_> systemd seems to strip of the quotes mbiebl_> systemctl status shows mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS $RootDir $MountPoint mbiebl_> which is pretty weird --- src/shared/strv.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/shared/strv.c') diff --git a/src/shared/strv.c b/src/shared/strv.c index b4c476eff2..0ac66b927c 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -201,8 +201,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) { } char **strv_split(const char *s, const char *separator) { - char *state; - char *w; + const char *word, *state; size_t l; unsigned n, i; char **r; @@ -210,7 +209,7 @@ char **strv_split(const char *s, const char *separator) { assert(s); n = 0; - FOREACH_WORD_SEPARATOR(w, l, s, separator, state) + FOREACH_WORD_SEPARATOR(word, l, s, separator, state) n++; r = new(char*, n+1); @@ -218,8 +217,8 @@ char **strv_split(const char *s, const char *separator) { return NULL; i = 0; - FOREACH_WORD_SEPARATOR(w, l, s, separator, state) { - r[i] = strndup(w, l); + FOREACH_WORD_SEPARATOR(word, l, s, separator, state) { + r[i] = strndup(word, l); if (!r[i]) { strv_free(r); return NULL; @@ -233,8 +232,7 @@ char **strv_split(const char *s, const char *separator) { } char **strv_split_quoted(const char *s) { - char *state; - char *w; + const char *word, *state; size_t l; unsigned n, i; char **r; @@ -242,16 +240,19 @@ char **strv_split_quoted(const char *s) { assert(s); n = 0; - FOREACH_WORD_QUOTED(w, l, s, state) + FOREACH_WORD_QUOTED(word, l, s, state) n++; + if (*state) + /* bad syntax */ + return NULL; r = new(char*, n+1); if (!r) return NULL; i = 0; - FOREACH_WORD_QUOTED(w, l, s, state) { - r[i] = cunescape_length(w, l); + FOREACH_WORD_QUOTED(word, l, s, state) { + r[i] = cunescape_length(word, l); if (!r[i]) { strv_free(r); return NULL; -- cgit v1.2.3-54-g00ecf