[OpenWrt-Devel] [PATCH fstools] libfstools: ubi: avoid crash in volume finding function

Rafał Miłecki zajec5 at gmail.com
Tue Dec 23 15:33:49 EST 2014


In case /sys/devices/virtual/ubi/ubi?/ubi?_?/name doesn't exist volname
will be NULL and calling strlen for NULL isn't a good idea.

Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
---
 libfstools/ubi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libfstools/ubi.c b/libfstools/ubi.c
index 866034a..ac9eb1b 100644
--- a/libfstools/ubi.c
+++ b/libfstools/ubi.c
@@ -143,6 +143,10 @@ static int ubi_volume_match(struct volume *v, char *name, int ubi_num, int volid
 	/* todo: skip existing gluebi device for legacy support */
 
 	volname = read_string_from_file(voldir, "name");
+	if (!volname) {
+		fprintf(stderr, "Couldn't read %s/name\n", voldir);
+		return -1;
+	}
 
 	if (strncmp(name, volname, strlen(volname) + 1))
 		return -1;
-- 
1.8.4.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list