From: Karel Zak Date: Thu, 25 Nov 2021 10:54:11 +0000 (+0100) Subject: libblkid: check UBI char device name X-Git-Tag: v2.38-rc1~147 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7eb6d9ce4526b968e30f7e538cbbbdf9938e5891;p=thirdparty%2Futil-linux.git libblkid: check UBI char device name Signed-off-by: Karel Zak --- diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 0207f79c15..3685ea5e13 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -931,9 +931,17 @@ int blkid_probe_set_device(blkid_probe pr, int fd, DBG(LOWPROBE, ul_debug("failed to get device size")); goto err; } - } else if (S_ISCHR(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)) + || strncmp(buf, "ubi", 3) != 0) { + DBG(LOWPROBE, ul_debug("no UBI char device")); + errno = EINVAL; + goto err; + } devsiz = 1; /* UBI devices are char... */ - else if (S_ISREG(sb.st_mode)) + } else if (S_ISREG(sb.st_mode)) devsiz = sb.st_size; /* regular file */ pr->size = size ? (uint64_t)size : devsiz;