summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorMartin Pitt <martinpitt@users.noreply.github.com>2017-04-29 21:19:24 +0200
committerGitHub <noreply@github.com>2017-04-29 21:19:24 +0200
commit815e542b7caee5166668180c8014e29bfe3bf1f8 (patch)
treeafba4ca09ba29a81ef8f0d8a1850df011a62d36f /src/core
parent5b3cc0c86aeddd4615e7e28e79aa89e5b77a6507 (diff)
parentd8c92e8bc7351f553936b5235e1922c18ebd817a (diff)
Merge pull request #5809 from keszybz/glob-safe
Implement `safe_glob` that ignores "." and ".."
Diffstat (limited to 'src/core')
-rw-r--r--src/core/execute.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/core/execute.c b/src/core/execute.c
index 2056e2273c..9c1aa4cf98 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -3231,11 +3231,10 @@ int exec_context_load_environment(Unit *unit, const ExecContext *c, char ***l) {
STRV_FOREACH(i, c->environment_files) {
char *fn;
- int k;
+ int k, n;
bool ignore = false;
char **p;
_cleanup_globfree_ glob_t pglob = {};
- int count, n;
fn = *i;
@@ -3253,23 +3252,19 @@ int exec_context_load_environment(Unit *unit, const ExecContext *c, char ***l) {
}
/* Filename supports globbing, take all matching files */
- errno = 0;
- if (glob(fn, 0, NULL, &pglob) != 0) {
+ k = safe_glob(fn, 0, &pglob);
+ if (k < 0) {
if (ignore)
continue;
strv_free(r);
- return errno > 0 ? -errno : -EINVAL;
+ return k;
}
- count = pglob.gl_pathc;
- if (count == 0) {
- if (ignore)
- continue;
- strv_free(r);
- return -EINVAL;
- }
- for (n = 0; n < count; n++) {
+ /* When we don't match anything, -ENOENT should be returned */
+ assert(pglob.gl_pathc > 0);
+
+ for (n = 0; n < pglob.gl_pathc; n++) {
k = load_env_file(NULL, pglob.gl_pathv[n], NULL, &p);
if (k < 0) {
if (ignore)