summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2015-10-22 20:28:28 +0000
committerEvgeny Vereshchagin <evvers@ya.ru>2015-10-22 20:28:28 +0000
commit727f76d715e297f6e0ae409d5d9b1c8aa3c8987b (patch)
treee90050713e279a87ae80311128bd58f35c1bd9bb /src/core/load-fragment.c
parentb8c89d3c4255e1f2ad9bf49eabe89d50c419783e (diff)
core: use extract_first_word for namespace parsing
see https://github.com/systemd/systemd/pull/1632#issuecomment-149903791 We should port this loop over to extract_first_word(), too.
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r--src/core/load-fragment.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index b36f5d532b..a361de2a4a 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3193,8 +3193,8 @@ int config_parse_namespace_path_strv(
void *userdata) {
char*** sv = data;
- const char *word, *state;
- size_t l;
+ const char *prev;
+ const char *cur;
int r;
assert(filename);
@@ -3208,35 +3208,41 @@ int config_parse_namespace_path_strv(
return 0;
}
- FOREACH_WORD_QUOTED(word, l, rvalue, state) {
- _cleanup_free_ char *n;
+ prev = cur = rvalue;
+ for (;;) {
+ _cleanup_free_ char *word = NULL;
int offset;
- n = strndup(word, l);
- if (!n)
- return log_oom();
+ r = extract_first_word(&cur, &word, NULL, EXTRACT_QUOTES);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring: %s", prev);
+ return 0;
+ }
+ if (r == 0)
+ break;
- if (!utf8_is_valid(n)) {
- log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
+ if (!utf8_is_valid(word)) {
+ log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, word);
+ prev = cur;
continue;
}
- offset = n[0] == '-';
- if (!path_is_absolute(n + offset)) {
- log_syntax(unit, LOG_ERR, filename, line, 0, "Not an absolute path, ignoring: %s", rvalue);
+ offset = word[0] == '-';
+ if (!path_is_absolute(word + offset)) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Not an absolute path, ignoring: %s", word);
+ prev = cur;
continue;
}
- path_kill_slashes(n + offset);
+ path_kill_slashes(word + offset);
- r = strv_push(sv, n);
+ r = strv_push(sv, word);
if (r < 0)
return log_oom();
- n = NULL;
+ prev = cur;
+ word = NULL;
}
- if (!isempty(state))
- log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring.");
return 0;
}