]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
home: fix use of uninitialized value
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Oct 2021 07:27:50 +0000 (16:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Oct 2021 12:51:44 +0000 (21:51 +0900)
Fixes CID#1465077.

src/home/homework-luks.c

index d1208e4678784cd753ac37d03b5aa2610f7b54f7..7aee82a980e5fbc8ead88abd6cf52d8f0687a89c 100644 (file)
@@ -1278,6 +1278,7 @@ int home_setup_luks(
                         return log_error_errno(errno, "Failed to open home directory: %m");
         } else {
                 _cleanup_free_ char *fstype = NULL, *subdir = NULL;
+                bool has_stat = false;
                 const char *ip;
                 struct stat st;
 
@@ -1292,6 +1293,8 @@ int home_setup_luks(
                         setup->image_fd = open_image_file(h, force_image_path, &st);
                         if (setup->image_fd < 0)
                                 return setup->image_fd;
+
+                        has_stat = true;
                 }
 
                 r = luks_validate(setup->image_fd, user_record_user_name_and_realm(h), h->partition_uuid, &found_partition_uuid, &offset, &size);
@@ -1304,7 +1307,7 @@ int home_setup_luks(
                         setup->do_mark_clean = true;
 
                 if (!user_record_luks_discard(h)) {
-                        r = run_fallocate(setup->image_fd, &st);
+                        r = run_fallocate(setup->image_fd, has_stat ? &st : NULL);
                         if (r < 0)
                                 return r;
                 }