From 36556f6e514095d220d1cdb37697a07f4b6061d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Feb 2021 14:19:36 +0100 Subject: [PATCH] systemctl: use free_and_replace on global variable In normal usage we cannot set it multiple times, but from a fuzzer we may. Doing it this way is nicer anyway. --- src/systemctl/systemctl-compat-shutdown.c | 5 +++-- src/systemctl/systemctl.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/systemctl/systemctl-compat-shutdown.c b/src/systemctl/systemctl-compat-shutdown.c index d876c79d33..11154f5f8b 100644 --- a/src/systemctl/systemctl-compat-shutdown.c +++ b/src/systemctl/systemctl-compat-shutdown.c @@ -132,9 +132,10 @@ int shutdown_parse_argv(int argc, char *argv[]) { wall = argv + optind + 1; if (wall) { - arg_wall = strv_copy(wall); - if (!arg_wall) + char **copy = strv_copy(wall); + if (!copy) return log_oom(); + strv_free_and_replace(arg_wall, copy); } optind = argc; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index b82e541d7a..b27da5dad9 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1159,8 +1159,8 @@ static int run(int argc, char *argv[]) { case ACTION_SUSPEND_THEN_HIBERNATE: case ACTION_EMERGENCY: case ACTION_DEFAULT: - /* systemctl verbs with no equivalent in the legacy commands. These cannot appear in - * arg_action. Fall through. */ + /* systemctl verbs with no equivalent in the legacy commands. These cannot appear in + * arg_action. Fall through. */ case _ACTION_INVALID: default: -- 2.25.1