e2bea3e210
Fix double free on buggy old kernel sysfs read Fix segfault if trying to write superblock to non existing device Resolves: bz795707 (f17) bz795747 (f16) bz795748 (f15) Resolves: bz795461 (f17) bz795749 (f16) bz795750 (f15) Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
95 lines
2.3 KiB
Diff
95 lines
2.3 KiB
Diff
From 4011421332681ba733a2fc90de7ac94da8593418 Mon Sep 17 00:00:00 2001
|
|
From: Jes Sorensen <Jes.Sorensen@redhat.com>
|
|
Date: Thu, 23 Feb 2012 08:55:19 +1100
|
|
Subject: [PATCH 2/2] Print error message if failing to write super for 1.x
|
|
metadata
|
|
|
|
In addition remove attempt to print an error message if
|
|
write_init_super() fails, as this is handled in the various
|
|
write_init_super() functions. This avoids a segfault on error.
|
|
|
|
Reported by Jim Meyering in
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=795461
|
|
|
|
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
|
|
Signed-off-by: NeilBrown <neilb@suse.de>
|
|
---
|
|
Create.c | 3 ---
|
|
super1.c | 25 ++++++++++++++++---------
|
|
2 files changed, 16 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/Create.c b/Create.c
|
|
index 90ff3ed..e5c6b05 100644
|
|
--- a/Create.c
|
|
+++ b/Create.c
|
|
@@ -924,9 +924,6 @@ int Create(struct supertype *st, char *mddev,
|
|
}
|
|
|
|
if (st->ss->write_init_super(st)) {
|
|
- fprintf(stderr,
|
|
- Name ": Failed to write metadata to %s\n",
|
|
- dv->devname);
|
|
st->ss->free_super(st);
|
|
goto abort_locked;
|
|
}
|
|
diff --git a/super1.c b/super1.c
|
|
index a18952a..341ad53 100644
|
|
--- a/super1.c
|
|
+++ b/super1.c
|
|
@@ -1106,13 +1106,16 @@ static int write_init_super1(struct supertype *st)
|
|
}
|
|
free(refst);
|
|
|
|
- if (!get_dev_size(di->fd, NULL, &dsize))
|
|
- return 1;
|
|
+ if (!get_dev_size(di->fd, NULL, &dsize)) {
|
|
+ rv = 1;
|
|
+ goto error_out;
|
|
+ }
|
|
dsize >>= 9;
|
|
|
|
if (dsize < 24) {
|
|
close(di->fd);
|
|
- return 2;
|
|
+ rv = 2;
|
|
+ goto error_out;
|
|
}
|
|
|
|
|
|
@@ -1176,22 +1179,26 @@ static int write_init_super1(struct supertype *st)
|
|
sb->data_size = __cpu_to_le64(dsize - reserved);
|
|
break;
|
|
default:
|
|
- return -EINVAL;
|
|
+ fprintf(stderr, Name ": Failed to write invalid "
|
|
+ "metadata format 1.%i to %s\n",
|
|
+ st->minor_version, di->devname);
|
|
+ rv = -EINVAL;
|
|
+ goto out;
|
|
}
|
|
|
|
|
|
sb->sb_csum = calc_sb_1_csum(sb);
|
|
rv = store_super1(st, di->fd);
|
|
- if (rv)
|
|
- fprintf(stderr,
|
|
- Name ": failed to write superblock to %s\n",
|
|
- di->devname);
|
|
-
|
|
if (rv == 0 && (__le32_to_cpu(sb->feature_map) & 1))
|
|
rv = st->ss->write_bitmap(st, di->fd);
|
|
close(di->fd);
|
|
di->fd = -1;
|
|
}
|
|
+error_out:
|
|
+ if (rv)
|
|
+ fprintf(stderr, Name ": Failed to write metadata to %s\n",
|
|
+ di->devname);
|
|
+out:
|
|
return rv;
|
|
}
|
|
#endif
|
|
--
|
|
1.7.7.6
|
|
|