From e9d0fa8c68d531529a3988bbf83ebb2900c11c0d Mon Sep 17 00:00:00 2001 From: majianpeng Date: Tue, 29 May 2012 09:21:51 +1000 Subject: mdadm: Fix Segmentation fault. 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 Signed-off-by: NeilBrown --- super1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/super1.c b/super1.c index 871af3f..26f9974 100644 --- 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) -- cgit v1.2.1