libfstools: ubi: avoid crash in volume finding function
authorRafał Miłecki <zajec5@gmail.com>
Tue, 23 Dec 2014 20:33:49 +0000 (21:33 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 6 Jan 2015 11:08:04 +0000 (12:08 +0100)
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

index 866034a7cc84e4d06e495b18d87be85ec658ca8a..ac9eb1b976851e1e4322edace5018cd44265d488 100644 (file)
@@ -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;