]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: Fix Segmentation fault. data_offset
authormajianpeng <majianpeng@gmail.com>
Mon, 28 May 2012 23:21:51 +0000 (09:21 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 5 Jun 2012 05:41:14 +0000 (15:41 +1000)
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>
Signed-off-by: NeilBrown <neilb@suse.de>
super1.c

index 871af3f0806de199a5cfef56070a5f48f583f2e3..26f99745514a82b78ff38dc69680323cb89f5769 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -1162,7 +1162,7 @@ static int write_init_super1(struct supertype *st)
        unsigned long long sb_offset, headroom;
        long long data_offset;
 
-       for (di = st->info; di && ! rv ; di = di->next) {
+       for (di = st->info; di; di = di->next) {
                if (di->disk.state == 1)
                        continue;
                if (di->fd < 0)
@@ -1321,6 +1321,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)