dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
25f9c8
From 90783d6294351229efdee5469dd8cd08d0057731 Mon Sep 17 00:00:00 2001
25f9c8
From: Karel Zak <kzak@redhat.com>
25f9c8
Date: Thu, 25 Nov 2021 11:54:26 +0100
25f9c8
Subject: [PATCH 72/74] blkid: check device type and name before probe
25f9c8
25f9c8
For calls "blkid /dev/*", it seems better to check the
25f9c8
device type and name before we open the device in libblkid.
25f9c8
25f9c8
Upstream: http://github.com/util-linux/util-linux/commit/64cfe6ac37631a6347bd4005c72dd2d37e737f5e
25f9c8
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2026511
25f9c8
Signed-off-by: Karel Zak <kzak@redhat.com>
25f9c8
---
25f9c8
 misc-utils/blkid.c | 27 +++++++++++++++++++++++++--
25f9c8
 1 file changed, 25 insertions(+), 2 deletions(-)
25f9c8
25f9c8
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
25f9c8
index 61a6994c2..bd4ce4a39 100644
25f9c8
--- a/misc-utils/blkid.c
25f9c8
+++ b/misc-utils/blkid.c
25f9c8
@@ -46,6 +46,8 @@
25f9c8
 #define XALLOC_EXIT_CODE    BLKID_EXIT_OTHER    /* x.*alloc(), xstrndup() */
25f9c8
 #include "xalloc.h"
25f9c8
 
25f9c8
+#include "sysfs.h"
25f9c8
+
25f9c8
 struct blkid_control {
25f9c8
 	int output;
25f9c8
 	uintmax_t offset;
25f9c8
@@ -813,8 +815,29 @@ int main(int argc, char **argv)
25f9c8
 	/* The rest of the args are device names */
25f9c8
 	if (optind < argc) {
25f9c8
 		devices = xcalloc(argc - optind, sizeof(char *));
25f9c8
-		while (optind < argc)
25f9c8
-			devices[numdev++] = argv[optind++];
25f9c8
+		while (optind < argc) {
25f9c8
+			char *dev = argv[optind++];
25f9c8
+			struct stat sb;
25f9c8
+
25f9c8
+			if (stat(dev, &sb) != 0)
25f9c8
+				continue;
25f9c8
+			else if (S_ISBLK(sb.st_mode))
25f9c8
+				;
25f9c8
+			else if (S_ISREG(sb.st_mode))
25f9c8
+				;
25f9c8
+			else if (S_ISCHR(sb.st_mode)) {
25f9c8
+				char buf[PATH_MAX];
25f9c8
+
25f9c8
+				if (!sysfs_chrdev_devno_to_devname(
25f9c8
+						sb.st_rdev, buf, sizeof(buf)))
25f9c8
+					continue;
25f9c8
+				if (strncmp(buf, "ubi", 3) != 0)
25f9c8
+					continue;
25f9c8
+			} else
25f9c8
+				continue;
25f9c8
+
25f9c8
+			devices[numdev++] = dev;
25f9c8
+		}
25f9c8
 	}
25f9c8
 
25f9c8
 	/* convert LABEL/UUID lookup to evaluate request */
25f9c8
-- 
25f9c8
2.31.1
25f9c8