From 0e04a66789b8e9cb93d4c49bf88fba8a66e6b81a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 8 Sep 2021 12:52:43 +0200 Subject: [PATCH] lsfd: fix ASSOC_EXE use, make file->association use more robust 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 --- misc-utils/lsfd.c | 15 ++++++++++----- misc-utils/lsfd.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 60c5ab0c9a..4f65e38c49 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -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, diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 0eb65978e9..178ca3396d 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -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; -- 2.47.2