mdadm: monitor: fix nullptr dereference when get_md_name() returns NULL

Function add_new_arrays() expects that function get_md_name() should
return pointer to devname, but also get_md_name() may return NULL. So
check the pointer before use it in add_new_arrays().

Signed-off-by: Sergey Vidishev <sergeyv@yandex-team.ru>
Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
Sergey Vidishev 2015-05-19 22:02:46 +03:00 committed by NeilBrown
parent dd0468af57
commit 1e08717f0b
1 changed files with 9 additions and 1 deletions

View File

@ -687,6 +687,7 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
{
struct mdstat_ent *mse;
int new_found = 0;
char *name;
for (mse=mdstat; mse; mse=mse->next)
if (mse->devnm[0] &&
@ -697,7 +698,14 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
struct state *st = xcalloc(1, sizeof *st);
mdu_array_info_t array;
int fd;
st->devname = xstrdup(get_md_name(mse->devnm));
name = get_md_name(mse->devnm);
if (!name) {
free(st);
continue;
}
st->devname = xstrdup(name);
if ((fd = open(st->devname, O_RDONLY)) < 0 ||
ioctl(fd, GET_ARRAY_INFO, &array)< 0) {
/* no such array */