dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0072-blkid-check-device-type-and-name-before-probe.patch

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