]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: fix ASSOC_EXE use, make file->association use more robust
authorKarel Zak <kzak@redhat.com>
Wed, 8 Sep 2021 10:52:43 +0000 (12:52 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:54 +0000 (11:01 +0200)
Let's use is_association() macro in the code rather than directly
check file->association as this struct member has special semantic.

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsfd.c
misc-utils/lsfd.h

index 60c5ab0c9aa4eb379143d4aa760ba1ce3b4b7c12..4f65e38c493c8ae2d4f287c5b22790b1ac0bea9f 100644 (file)
@@ -269,7 +269,7 @@ static struct file *new_file(
        INIT_LIST_HEAD(&file->files);
        list_add_tail(&file->files, &proc->files);
 
-       if (file->association == -ASSOC_SHM || file->association == -ASSOC_MEM) {
+       if (is_association(file, SHM) || is_association(file, MEM)) {
                static size_t pagesize = 0;
 
                assert(map_file_data);
@@ -559,16 +559,21 @@ static struct file *collect_outofbox_file(struct path_cxt *pc,
 {
        char sym[PATH_MAX] = { '\0' };
        struct stat sb;
+       struct file *f;
 
        if (ul_path_stat(pc, &sb, name) < 0)
                return NULL;
-       if (assoc == ASSOC_EXE)
-               proc->uid = sb.st_uid;
-
        if (ul_path_readlink(pc, sym, sizeof(sym), name) < 0)
                return NULL;
 
-       return new_file(proc, &sb, sym, NULL, assoc);
+       f = new_file(proc, &sb, sym, NULL, assoc);
+       if (!f)
+               return NULL;
+
+       if (is_association(f, EXE))
+               proc->uid = sb.st_uid;
+
+       return f;
 }
 
 static void collect_outofbox_files(struct path_cxt *pc,
index 0eb65978e964f7450c00c79aceb6fb3d6f5a59c9..178ca3396d215cf26ed07b9eaa7b5e7a80c053d5 100644 (file)
@@ -126,6 +126,8 @@ struct file {
        } assoc_data;
 };
 
+#define is_association(_f, a)  ((_f)->association < 0 && (_f)->association == -ASSOC_ ## a)
+
 struct file_class {
        const struct file_class *super;
        size_t size;