summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-31 03:28:37 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-31 08:56:03 -0400
commitb2fadec6048adb3596f2633cb7fe7a49f5937a18 (patch)
tree8969997ed3730146ff98774b14b3dcd65392c4df /src/shared
parenta2a5291b3f5ab6ed4c92f51d0fd10a03047380d8 (diff)
Properly report invalid quoted strings
$ systemd-analyze verify trailing-g.service [./trailing-g.service:2] Trailing garbage, ignoring. trailing-g.service lacks ExecStart setting. Refusing. Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument. Failed to create trailing-g.service/start: Invalid argument
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/condition-util.c2
-rw-r--r--src/shared/conf-parser.c3
-rw-r--r--src/shared/install.c3
-rw-r--r--src/shared/log.c2
-rw-r--r--src/shared/strv.c13
-rw-r--r--src/shared/strv.h2
-rw-r--r--src/shared/util.c34
7 files changed, 38 insertions, 21 deletions
diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c
index f88ddc19e2..b52dcc52f9 100644
--- a/src/shared/condition-util.c
+++ b/src/shared/condition-util.c
@@ -114,6 +114,8 @@ bool condition_test_kernel_command_line(Condition *c) {
}
}
+ if (!isempty(state))
+ log_warning("Trailing garbage and the end of kernel commandline, ignoring.");
free(word);
free(line);
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index cd189adfc3..439cfc58fc 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -717,6 +717,9 @@ int config_parse_strv(const char *unit,
if (r < 0)
return log_oom();
}
+ if (!isempty(state))
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Trailing garbage, ignoring.");
return 0;
}
diff --git a/src/shared/install.c b/src/shared/install.c
index c32d6599a6..276ca3ec7a 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -966,6 +966,9 @@ static int config_parse_also(
if (r < 0)
return r;
}
+ if (!isempty(state))
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Trailing garbage, ignoring.");
return 0;
}
diff --git a/src/shared/log.c b/src/shared/log.c
index a7c3195f39..078ccdc35b 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -880,6 +880,8 @@ void log_parse_environment(void) {
break;
}
}
+ if (!isempty(state))
+ log_warning("Trailing garbage and the end of kernel commandline, ignoring.");
}
e = secure_getenv("SYSTEMD_LOG_TARGET");
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 0ac66b927c..6448f3170f 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -231,7 +231,7 @@ char **strv_split(const char *s, const char *separator) {
return r;
}
-char **strv_split_quoted(const char *s) {
+int strv_split_quoted(char ***t, const char *s) {
const char *word, *state;
size_t l;
unsigned n, i;
@@ -242,26 +242,27 @@ char **strv_split_quoted(const char *s) {
n = 0;
FOREACH_WORD_QUOTED(word, l, s, state)
n++;
- if (*state)
+ if (!isempty(state))
/* bad syntax */
- return NULL;
+ return -EINVAL;
r = new(char*, n+1);
if (!r)
- return NULL;
+ return -ENOMEM;
i = 0;
FOREACH_WORD_QUOTED(word, l, s, state) {
r[i] = cunescape_length(word, l);
if (!r[i]) {
strv_free(r);
- return NULL;
+ return -ENOMEM;
}
i++;
}
r[i] = NULL;
- return r;
+ *t = r;
+ return 0;
}
char **strv_split_newlines(const char *s) {
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 3034073d32..ee55c148aa 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -62,7 +62,7 @@ static inline bool strv_isempty(char * const *l) {
}
char **strv_split(const char *s, const char *separator);
-char **strv_split_quoted(const char *s);
+int strv_split_quoted(char ***t, const char *s);
char **strv_split_newlines(const char *s);
char *strv_join(char **l, const char *separator);
diff --git a/src/shared/util.c b/src/shared/util.c
index cb9687cb02..76cee19261 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3163,12 +3163,13 @@ fail:
}
char **replace_env_argv(char **argv, char **env) {
- char **r, **i;
+ char **ret, **i;
unsigned k = 0, l = 0;
l = strv_length(argv);
- if (!(r = new(char*, l+1)))
+ ret = new(char*, l+1);
+ if (!ret)
return NULL;
STRV_FOREACH(i, argv) {
@@ -3181,10 +3182,12 @@ char **replace_env_argv(char **argv, char **env) {
e = strv_env_get(env, *i+1);
if (e) {
+ int r;
- if (!(m = strv_split_quoted(e))) {
- r[k] = NULL;
- strv_free(r);
+ r = strv_split_quoted(&m, e);
+ if (r < 0) {
+ ret[k] = NULL;
+ strv_free(ret);
return NULL;
}
} else
@@ -3193,16 +3196,17 @@ char **replace_env_argv(char **argv, char **env) {
q = strv_length(m);
l = l + q - 1;
- if (!(w = realloc(r, sizeof(char*) * (l+1)))) {
- r[k] = NULL;
- strv_free(r);
+ w = realloc(ret, sizeof(char*) * (l+1));
+ if (!w) {
+ ret[k] = NULL;
+ strv_free(ret);
strv_free(m);
return NULL;
}
- r = w;
+ ret = w;
if (m) {
- memcpy(r + k, m, q * sizeof(char*));
+ memcpy(ret + k, m, q * sizeof(char*));
free(m);
}
@@ -3211,14 +3215,16 @@ char **replace_env_argv(char **argv, char **env) {
}
/* If ${FOO} appears as part of a word, replace it by the variable as-is */
- if (!(r[k++] = replace_env(*i, env))) {
- strv_free(r);
+ ret[k] = replace_env(*i, env);
+ if (!ret[k]) {
+ strv_free(ret);
return NULL;
}
+ k++;
}
- r[k] = NULL;
- return r;
+ ret[k] = NULL;
+ return ret;
}
int fd_columns(int fd) {