block: fix possible NULL pointer dereference in mount_device()
[project/ubox.git] / block.c
diff --git a/block.c b/block.c
index ea14248..860a95c 100644 (file)
--- a/block.c
+++ b/block.c
@@ -327,7 +327,7 @@ static int _cache_load(const char *path)
                struct blkid_struct_probe *pr = malloc(sizeof(struct blkid_struct_probe));
                memset(pr, 0, sizeof(struct blkid_struct_probe));
                probe_block(gl.gl_pathv[j], pr);
-               if (pr->err)
+               if (pr->err || !pr->id)
                        free(pr);
                else
                        list_add_tail(&pr->list, &devices);
@@ -346,6 +346,8 @@ static void cache_load(int mtd)
        _cache_load("/dev/sd*");
        _cache_load("/dev/sdc*");
        _cache_load("/dev/hd*");
+       _cache_load("/dev/md*");
+       _cache_load("/dev/mapper/*");
 }
 
 static int print_block_info(struct blkid_struct_probe *pr)
@@ -479,11 +481,13 @@ static void check_filesystem(struct blkid_struct_probe *pr)
 static int mount_device(struct blkid_struct_probe *pr, int hotplug)
 {
        struct mount *m;
-       char *device = basename(pr->dev);
+       char *device;
 
        if (!pr)
                return -1;
 
+       device = basename(pr->dev);
+
        if (!strcmp(pr->id->name, "swap")) {
                if (hotplug && !auto_swap)
                        return -1;