From: Karel Zak Date: Thu, 25 Nov 2021 10:54:26 +0000 (+0100) Subject: blkid: check device type and name before probe X-Git-Tag: v2.38-rc1~146 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64cfe6ac37631a6347bd4005c72dd2d37e737f5e;p=thirdparty%2Futil-linux.git blkid: check device type and name before probe 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 --- diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index cccd8af872..41826e6dc4 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -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 */