summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-27 22:37:52 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-28 18:42:18 +0100
commit70f75a523b16ad495a7791d595ee3eececf75953 (patch)
tree1ee6c3161a45a58ab58ef8627de43394a6c4eef1 /src/shared
parentfb1454005dda75cdab5795285a8607237033d6a8 (diff)
util: fix handling of trailing whitespace in split_quoted()
Inspired by a patch by Lukas Nykryn.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index d31bd52949..0fce2537da 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -373,17 +373,21 @@ char *split(const char *c, size_t *l, const char *separator, char **state) {
/* Split a string into words, but consider strings enclosed in '' and
* "" as words even if they include spaces. */
char *split_quoted(const char *c, size_t *l, char **state) {
- char *current, *e;
+ const char *current, *e;
bool escaped = false;
- current = *state ? *state : (char*) c;
+ assert(c);
+ assert(l);
+ assert(state);
- if (!*current || *c == 0)
- return NULL;
+ current = *state ? *state : c;
current += strspn(current, WHITESPACE);
- if (*current == '\'') {
+ if (*current == 0)
+ return NULL;
+
+ else if (*current == '\'') {
current ++;
for (e = current; *e; e++) {
@@ -396,7 +400,8 @@ char *split_quoted(const char *c, size_t *l, char **state) {
}
*l = e-current;
- *state = *e == 0 ? e : e+1;
+ *state = (char*) (*e == 0 ? e : e+1);
+
} else if (*current == '\"') {
current ++;
@@ -410,7 +415,8 @@ char *split_quoted(const char *c, size_t *l, char **state) {
}
*l = e-current;
- *state = *e == 0 ? e : e+1;
+ *state = (char*) (*e == 0 ? e : e+1);
+
} else {
for (e = current; *e; e++) {
if (escaped)
@@ -421,10 +427,10 @@ char *split_quoted(const char *c, size_t *l, char **state) {
break;
}
*l = e-current;
- *state = e;
+ *state = (char*) e;
}
- return (char*) current;
+ return current;
}
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {