]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/sleep-config: fix potential SEGV
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 8 Nov 2019 09:25:31 +0000 (10:25 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 9 Nov 2019 09:19:36 +0000 (09:19 +0000)
We were looking at the wrong variable, and would always crash if this
comparison was reached. Fixes #13965.

Also, fix crash (_cleanup_ called on uninitialized variable) if we failed in
error path.

While at it, let's shorten some messages.

src/shared/sleep-config.c

index 03108b92cbe83ae6cb3629d5f2fdc9f195e52ce1..754a63c2d248c45be6118d6764c9fe37510282b7 100644 (file)
@@ -249,27 +249,28 @@ static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offse
 }
 
 static int read_resume_files(char **ret_resume, uint64_t *ret_resume_offset) {
-        _cleanup_free_ char *resume, *resume_offset_str = NULL;
+        _cleanup_free_ char *resume = NULL, *resume_offset_str = NULL;
         uint64_t resume_offset = 0;
         int r;
 
         r = read_one_line_file("/sys/power/resume", &resume);
         if (r < 0)
-                return log_debug_errno(r, "Error reading from /sys/power/resume: %m");
+                return log_debug_errno(r, "Error reading /sys/power/resume: %m");
 
         r = read_one_line_file("/sys/power/resume_offset", &resume_offset_str);
         if (r == -ENOENT)
                 log_debug("Kernel does not support resume_offset; swap file offset detection will be skipped.");
         else if (r < 0)
-                return log_debug_errno(r, "Error reading from /sys/power/resume_offset: %m");
+                return log_debug_errno(r, "Error reading /sys/power/resume_offset: %m");
         else {
                 r = safe_atou64(resume_offset_str, &resume_offset);
                 if (r < 0)
                         return log_error_errno(r, "Failed to parse value in /sys/power/resume_offset \"%s\": %m", resume_offset_str);
         }
 
-        if (resume_offset > 0 && streq(*ret_resume, "0:0")) {
-                log_debug("Found offset in /sys/power/resume_offset: %" PRIu64 "; no device id found in /sys/power/resume; ignoring resume_offset", resume_offset);
+        if (resume_offset > 0 && streq(resume, "0:0")) {
+                log_debug("Found offset in /sys/power/resume_offset: %" PRIu64 "; no device id found in /sys/power/resume; ignoring resume_offset",
+                          resume_offset);
                 resume_offset = 0;
         }