[Ocfs2-tools-devel] [PATCH 3/6] mkfs.ocfs2: Check the validity of variables before use
piaojun
piaojun at huawei.com
Wed Mar 25 23:52:01 PDT 2015
1. In get_state(), we need check if s is null before use.
2. In alloc_from_bitmap(), we need check if buf is null before use.
Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>
---
mkfs.ocfs2/mkfs.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index cf088f4..77d4534 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -1112,6 +1112,10 @@ get_state(int argc, char **argv)
optind++;
s = malloc(sizeof(State));
+ if (!s) {
+ com_err(progname, 0, "Unable to allocate State structure.");
+ exit(1);
+ }
memset(s, 0, sizeof(State));
if (optind < argc) {
@@ -2157,10 +2161,11 @@ alloc_from_bitmap(State *s, uint64_t num_bits, AllocBitmap *bitmap,
"start = %"PRIu64". used_bits = %u\n", num_bits, *num, *start,
bitmap->bm_record->bi.used_bits);
#endif
-
- while (num_bits--) {
- ocfs2_set_bit(start_bit, buf);
- start_bit++;
+ if (buf) {
+ while (num_bits--) {
+ ocfs2_set_bit(start_bit, buf);
+ start_bit++;
+ }
}
return 0;
-- 1.8.4.3
More information about the Ocfs2-tools-devel
mailing list