]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/Monitor: Fix NULL pointer dereference when stat2devnm return NULL
authorZhilong Liu <zlliu@suse.com>
Mon, 20 Mar 2017 05:21:41 +0000 (13:21 +0800)
committerJes Sorensen <Jes.Sorensen@gmail.com>
Mon, 27 Mar 2017 22:24:19 +0000 (18:24 -0400)
Wait(): stat2devnm() returns NULL for non block devices. Check the
pointer is valid derefencing it. This can happen when using --wait,
such as the 'f' and 'd' file type, causing a core dump.
such as: ./mdadm --wait /dev/md/

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
Monitor.c

index 802a9d9864b9cbec68ec8d2214642970070160a7..bdd3e63e40ee80cf509aba8e48fd216935962724 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -994,6 +994,7 @@ int Wait(char *dev)
 {
        struct stat stb;
        char devnm[32];
+       char *tmp;
        int rv = 1;
        int frozen_remaining = 3;
 
@@ -1002,7 +1003,12 @@ int Wait(char *dev)
                        strerror(errno));
                return 2;
        }
-       strcpy(devnm, stat2devnm(&stb));
+       tmp = stat2devnm(&stb);
+       if (!tmp) {
+               pr_err("%s is not a block device.\n", dev);
+               return 2;
+       }
+       strcpy(devnm, tmp);
 
        while(1) {
                struct mdstat_ent *ms = mdstat_read(1, 0);