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

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