summaryrefslogtreecommitdiff
path: root/src/shared/conf-parser.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-02-11 23:45:59 +0100
committerLennart Poettering <lennart@poettering.net>2013-02-11 23:54:30 +0100
commit853b8397acdebdd44777810e560403bae3756859 (patch)
treefebf18d2889507e15311af52a3674f64bcade7ee /src/shared/conf-parser.c
parent123b964a537c21e9ebaf849acefb23f0f13db785 (diff)
core: properly validate environment data from Environment= lines in unit files
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r--src/shared/conf-parser.c104
1 files changed, 25 insertions, 79 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 7f286096d2..c5dd26db52 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -668,12 +668,8 @@ int config_parse_strv(
void *data,
void *userdata) {
- char*** sv = data;
- char **n;
- char *w;
- unsigned k;
+ char *** sv = data, *w, *state;
size_t l;
- char *state;
int r;
assert(filename);
@@ -685,50 +681,27 @@ int config_parse_strv(
/* Empty assignment resets the list */
strv_free(*sv);
*sv = NULL;
+ return 0;
}
- k = strv_length(*sv);
- FOREACH_WORD_QUOTED(w, l, rvalue, state)
- k++;
-
- n = new(char*, k+1);
- if (!n)
- return log_oom();
-
- if (*sv)
- for (k = 0; (*sv)[k]; k++)
- n[k] = (*sv)[k];
- else
- k = 0;
-
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- n[k] = cunescape_length(w, l);
- if (!n[k]) {
- r = log_oom();
- goto fail;
- }
+ _cleanup_free_ char *n;
- if (!utf8_is_valid(n[k])) {
- log_error("[%s:%u] String is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
- free(n[k]);
+ n = cunescape_length(w, l);
+ if (!n)
+ return log_oom();
+
+ if (!utf8_is_valid(n)) {
+ log_error("[%s:%u] String is not UTF-8 clean, ignoring: %s", filename, line, rvalue);
continue;
}
- k++;
+ r = strv_extend(sv, n);
+ if (r < 0)
+ return log_oom();
}
- n[k] = NULL;
- free(*sv);
- *sv = n;
-
return 0;
-
-fail:
- for (; k > 0; k--)
- free(n[k-1]);
- free(n);
-
- return r;
}
int config_parse_path_strv(
@@ -741,12 +714,8 @@ int config_parse_path_strv(
void *data,
void *userdata) {
- char*** sv = data;
- char **n;
- char *w;
- unsigned k;
+ char*** sv = data, *w, *state;
size_t l;
- char *state;
int r;
assert(filename);
@@ -758,56 +727,33 @@ int config_parse_path_strv(
/* Empty assignment resets the list */
strv_free(*sv);
*sv = NULL;
+ return 0;
}
- k = strv_length(*sv);
- FOREACH_WORD_QUOTED(w, l, rvalue, state)
- k++;
-
- n = new(char*, k+1);
- if (!n)
- return log_oom();
-
- k = 0;
- if (*sv)
- for (; (*sv)[k]; k++)
- n[k] = (*sv)[k];
-
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- n[k] = strndup(w, l);
- if (!n[k]) {
- r = log_oom();
- goto fail;
- }
+ _cleanup_free_ char *n;
- if (!utf8_is_valid(n[k])) {
+ n = strndup(w, l);
+ if (!n)
+ return log_oom();
+
+ if (!utf8_is_valid(n)) {
log_error("[%s:%u] Path is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
- free(n[k]);
continue;
}
- if (!path_is_absolute(n[k])) {
+ if (!path_is_absolute(n)) {
log_error("[%s:%u] Not an absolute path, ignoring: %s", filename, line, rvalue);
- free(n[k]);
continue;
}
- path_kill_slashes(n[k]);
- k++;
+ path_kill_slashes(n);
+ r = strv_extend(sv, n);
+ if (r < 0)
+ return log_oom();
}
- n[k] = NULL;
- free(*sv);
- *sv = n;
-
return 0;
-
-fail:
- for (; k > 0; k--)
- free(n[k-1]);
- free(n);
-
- return r;
}
int config_parse_usec(