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 <Jes.Sorensen@redhat.com>
This commit is contained in:
Jes Sorensen 2016-03-07 11:49:03 -05:00
parent 30e19bf805
commit 2a1990c0f4
1 changed files with 4 additions and 0 deletions

View File

@ -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);