From: Jes Sorensen Date: Mon, 7 Mar 2016 16:49:03 +0000 (-0500) Subject: Manage: Manage_add(): Fix potential NULL pointer dereference X-Git-Tag: mdadm-4.0~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a1990c0f4bbb00920fafe7c8eec1b8837595d48;p=thirdparty%2Fmdadm.git Manage: Manage_add(): Fix potential NULL pointer dereference sysfs_read() may return NULL, so we should check the validity of the pointer before dereferencing it. Signed-off-by: Jes Sorensen --- diff --git a/Manage.c b/Manage.c index 414373fe..a812ba05 100644 --- a/Manage.c +++ b/Manage.c @@ -938,6 +938,10 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv, struct mdinfo *mdp; mdp = sysfs_read(fd, NULL, GET_ARRAY_STATE); + if (!mdp) { + pr_err("%s unable to read array state.\n", devname); + return -1; + } if (strncmp(mdp->sysfs_array_state, "readonly", 8) != 0) { pr_err("%s is not readonly, cannot add journal.\n", devname);