diff mbox

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

Message ID 1419366829-27051-1-git-send-email-zajec5@gmail.com
State Accepted
Headers show

Commit Message

Rafał Miłecki Dec. 23, 2014, 8:33 p.m. UTC
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@gmail.com>
---
 libfstools/ubi.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox

Patch

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;