]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: avoid accessing an uninitialized value
authorMasatake YAMATO <yamato@redhat.com>
Thu, 3 Oct 2024 06:17:01 +0000 (15:17 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 3 Oct 2024 06:20:43 +0000 (15:20 +0900)
sb, a local variable in collect_file_symlink, accessed
at

bool is_socket = (sb.st_mode & S_IFMT) == S_IFSOCK;

was not initialized if copy_file path is taken.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsfd-cmd/lsfd.c

index 6b93016d997f09b701fd72ef80dc98d015aeddbb..09ef9a588366098d2c4fd0a8c9b63aa1bf17f3e9 100644 (file)
@@ -849,9 +849,10 @@ static struct file *collect_file_symlink(struct path_cxt *pc,
         */
        else if ((prev = list_last_entry(&proc->files, struct file, files))
                 && (!prev->is_error)
-                && prev->name && strcmp(prev->name, sym) == 0)
+                && prev->name && strcmp(prev->name, sym) == 0) {
                f = copy_file(prev, assoc);
-       else if (ul_path_stat(pc, &sb, 0, name) < 0)
+               sb = prev->stat;
+       } else if (ul_path_stat(pc, &sb, 0, name) < 0)
                f = new_stat_error_file(proc, sym, errno, assoc);
        else {
                const struct file_class *class = stat2class(&sb);