From: NeilBrown <neilb@suse.de>
To: Sergey Vidishev <sergeyv@yandex-team.ru>
Cc: "David F." <df7729@gmail.com>,
"linux-raid@vger.kernel.org" <linux-raid@vger.kernel.org>
Subject: Re: [PATCH v3] mdadm: monitor: fix nullptr dereference when get_md_name() returns NULL
Date: Wed, 20 May 2015 13:16:51 +1000 [thread overview]
Message-ID: <20150520131651.2f184086@notabene.brown> (raw)
In-Reply-To: <7486089.5E28xkmWcx@sergeyv_box>
[-- Attachment #1: Type: text/plain, Size: 1824 bytes --]
On Tue, 19 May 2015 22:02:46 +0300 Sergey Vidishev <sergeyv@yandex-team.ru>
wrote:
> >From fce3be7200e84665cdae58ba44d5c61af094af3b Mon Sep 17 00:00:00 2001
> From: Sergey Vidishev <sergeyv@yandex-team.ru>
> Date: Tue, 19 May 2015 20:34:58 +0300
> Subject: [PATCH] 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>
> ---
>
> v2 -> v3: - continue instead of return
> - avoid mem leak (thanks to David F.)
> v1 -> v2: more verbose commit message
>
> Monitor.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/Monitor.c b/Monitor.c
> index 1cd378b..a530032 100644
> --- a/Monitor.c
> +++ b/Monitor.c
> @@ -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 */
Applied, thanks.
And thanks David for the review help!
NeilBrown
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
prev parent reply other threads:[~2015-05-20 3:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-10 13:23 [PATCH] monitor: fix nullptr dereference when get_md_name() returns NULL Sergey Vidishev
2015-05-18 23:33 ` [PATCH v2] mdadm: " Sergey Vidishev
2015-05-19 1:42 ` David F.
2015-05-19 18:39 ` Sergey Vidishev
2015-05-19 19:02 ` [PATCH v3] " Sergey Vidishev
2015-05-20 3:16 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150520131651.2f184086@notabene.brown \
--to=neilb@suse.de \
--cc=df7729@gmail.com \
--cc=linux-raid@vger.kernel.org \
--cc=sergeyv@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.