linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: majianpeng <majianpeng@gmail.com>
Cc: linux-raid <linux-raid@vger.kernel.org>
Subject: Re: [PATCH] mdadm: Fix Segmentation fault.
Date: Tue, 29 May 2012 09:23:30 +1000	[thread overview]
Message-ID: <20120529092330.1b7c611f@notabene.brown> (raw)
In-Reply-To: <201205251949358900592@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]

On Fri, 25 May 2012 19:49:40 +0800 "majianpeng" <majianpeng@gmail.com> wrote:

> In function write_init_super1():
> If "rv = store_super1(st, di->fd)" return error and the di is the last.
> Then the di = NULL && rv > 0, so exec:
> if (rv)
>     fprintf(stderr, Name ": Failed to write metadata to%s\n",
>      	 di->devname);
> will be segmentation fault.
> 
> Signed-off-by: majianpeng <majianpeng@gmail.com>
> ---
>  super1.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/super1.c b/super1.c
> index 4f20cc3..37b7a90 100644
> --- a/super1.c
> +++ b/super1.c
> @@ -1242,6 +1242,8 @@ static int write_init_super1(struct supertype *st)
>  			rv = st->ss->write_bitmap(st, di->fd);
>  		close(di->fd);
>  		di->fd = -1;
> +		if (rv)
> +			goto error_out;
>  	}
>  error_out:
>  	if (rv)

Thanks.
This doesn't only go wrong when di is the last.  If di is not the last it
will not crash, but it will report an error for the wrong device.

So thanks for finding this - I've applied you patch and also remove the
'&& ! rv' test from the 'for' loop as it is now pointless.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

      reply	other threads:[~2012-05-28 23:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25 11:49 [PATCH] mdadm: Fix Segmentation fault majianpeng
2012-05-28 23:23 ` 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=20120529092330.1b7c611f@notabene.brown \
    --to=neilb@suse.de \
    --cc=linux-raid@vger.kernel.org \
    --cc=majianpeng@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).