From 8d1ee64829966e55904f2dc0e3b2ab928bfcc737 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 21 Mar 2019 18:07:21 +0100 Subject: [PATCH] systemctl: make a copy of the "verb" from argv[] before forking off a child --- src/systemctl/systemctl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 9d94935d686..9d2115b7121 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -6356,7 +6356,7 @@ static int enable_sysv_units(const char *verb, char **args) { NULL, }; - _cleanup_free_ char *p = NULL, *q = NULL, *l = NULL; + _cleanup_free_ char *p = NULL, *q = NULL, *l = NULL, *v = NULL; bool found_native = false, found_sysv; const char *name; unsigned c = 1; @@ -6405,7 +6405,13 @@ static int enable_sysv_units(const char *verb, char **args) { argv[c++] = q; } - argv[c++] = verb; + /* Let's copy the verb, since it's still pointing directly into the original argv[] array we + * got passed, but safe_fork() is likely going to rewrite that for the new child */ + v = strdup(verb); + if (!v) + return log_oom(); + + argv[c++] = v; argv[c++] = basename(p); argv[c] = NULL; -- 2.47.3