]> granicus.if.org Git - psmisc/commitdiff
fuser: Check pathname only on non-block devices
authorCraig Small <csmall@dropbear.xyz>
Tue, 27 Oct 2020 10:59:25 +0000 (21:59 +1100)
committerCraig Small <csmall@dropbear.xyz>
Tue, 27 Oct 2020 11:05:36 +0000 (22:05 +1100)
The referenced commit we would check the pathname to
ensure it matched our target. This worked fine for
real files. However for block devices it would fail
because "/dev/sda1" doesn't match "/mnt/myfile".

We only check the pathname if the thing we are matching
against is not a block file.

Thanks to @MarsChan for the report and also the suggested
fix!

References:
 commit 5c979b38253d187a8ecb8e52a0878b8bb668894f
 psmisc/psmisc#31

Signed-off-by: Craig Small <csmall@dropbear.xyz>
ChangeLog
src/fuser.c

index 1a88488dccb7676fdd0f04f4561dd079fe63e101..3e77df6412946b8259c1f5360a3298043512d4ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ Changes in NEXT
 ===============
        * pstree: Do not crash on missing processes !21
        * fuser: Get less confused about duplicate dev_id !10
+       * fuser: Only check pathname on non-block devices !31
 
 Changes in 23.3
 ===============
index 70da121ddbc65932093ceaa1cd8e7fd370b29354..03e6237da46970ff7352dc8313c056066201022f 100644 (file)
@@ -1606,13 +1606,15 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head,
                                if (thedev != dev_tmp->device)
                                        continue;
 
-                               /* check the paths match */
-                               if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) {
-                                   if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0)
-                                       continue;
-                               } else {
-                                   if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0)
-                                       continue;
+                               /* check the paths match if it is not a block device */
+                               if (! S_ISBLK(dev_tmp->name->st.st_mode)) {
+                                   if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) {
+                                       if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0)
+                                           continue;
+                                   } else {
+                                       if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0)
+                                           continue;
+                                   }
                                }
                                if (access == ACCESS_FILE
                                    && (lstat(filepath, &lst) == 0)