]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkid: check device type and name before probe
authorKarel Zak <kzak@redhat.com>
Thu, 25 Nov 2021 10:54:26 +0000 (11:54 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 25 Nov 2021 10:54:26 +0000 (11:54 +0100)
For calls "blkid /dev/*", it seems better to check the
device type and name before we open the device in libblkid.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2026511
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/blkid.c

index cccd8af87287fc22a7f9982b5a93758e826053f6..41826e6dc4508c6b2bc15112bf5286cb843a2a79 100644 (file)
@@ -46,6 +46,8 @@
 #define XALLOC_EXIT_CODE    BLKID_EXIT_OTHER    /* x.*alloc(), xstrndup() */
 #include "xalloc.h"
 
+#include "sysfs.h"
+
 struct blkid_control {
        int output;
        uintmax_t offset;
@@ -836,8 +838,29 @@ int main(int argc, char **argv)
        /* The rest of the args are device names */
        if (optind < argc) {
                devices = xcalloc(argc - optind, sizeof(char *));
-               while (optind < argc)
-                       devices[numdev++] = argv[optind++];
+               while (optind < argc) {
+                       char *dev = argv[optind++];
+                       struct stat sb;
+
+                       if (stat(dev, &sb) != 0)
+                               continue;
+                       else if (S_ISBLK(sb.st_mode))
+                               ;
+                       else if (S_ISREG(sb.st_mode))
+                               ;
+                       else if (S_ISCHR(sb.st_mode)) {
+                               char buf[PATH_MAX];
+
+                               if (!sysfs_chrdev_devno_to_devname(
+                                               sb.st_rdev, buf, sizeof(buf)))
+                                       continue;
+                               if (strncmp(buf, "ubi", 3) != 0)
+                                       continue;
+                       } else
+                               continue;
+
+                       devices[numdev++] = dev;
+               }
        }
 
        /* convert LABEL/UUID lookup to evaluate request */