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;