sleep: properly pass verb to sleep script
authorLennart Poettering <lennart@poettering.net>
Mon, 17 Jun 2019 09:31:06 +0000 (11:31 +0200)
committerMichael Biebl <biebl@debian.org>
Wed, 4 Sep 2019 17:34:17 +0000 (18:34 +0100)
Another fall-out from our rewriting of argv[] now.

Fixes: #12782
(cherry picked from commit 98dc9d1f8f02ef968140a2d55ed91528e1ef8056)

Gbp-Pq: Name sleep-properly-pass-verb-to-sleep-script.patch

src/sleep/sleep.c

index 11aabaf923d2391d284cfe9460bb92d1ab0ec2e6..867477b6bfc21bd62d03ab63d3d926cce3bca556 100644 (file)
@@ -32,6 +32,8 @@
 
 static char* arg_verb = NULL;
 
+STATIC_DESTRUCTOR_REGISTER(arg_verb, freep);
+
 static int write_hibernate_location_info(void) {
         _cleanup_free_ char *device = NULL, *type = NULL;
         _cleanup_free_ struct fiemap *fiemap = NULL;
@@ -344,7 +346,9 @@ static int parse_argv(int argc, char *argv[]) {
                                        "Usage: %s COMMAND",
                                        program_invocation_short_name);
 
-        arg_verb = argv[optind];
+        arg_verb = strdup(argv[optind]);
+        if (!arg_verb)
+                return log_oom();
 
         if (!STR_IN_SET(arg_verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate"))
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),