From 470f8b1266be201818ae53f3353bae8acf78d8bc Mon Sep 17 00:00:00 2001 From: Jonathan Earl Brassow Date: Thu, 11 Aug 2011 19:17:10 +0000 Subject: [PATCH] Add some log_error msg's and fix potential segfault Thanks to kabi for spotting these - especially the possibility for segfault if a loop runs all the way through without finding a match. --- lib/metadata/raid_manip.c | 12 ++++++++---- libdm/libdm-deptree.c | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c index 59c2e10ee..1a8726a4a 100644 --- a/lib/metadata/raid_manip.c +++ b/lib/metadata/raid_manip.c @@ -179,16 +179,20 @@ static int _shift_and_rename_image_components(struct lv_segment *seg) /* Alter rmeta name */ shift_name = dm_pool_strdup(cmd->mem, seg_metalv(seg, s)->name); - if (!shift_name) - return_0; + if (!shift_name) { + log_error("Memory allocation failed."); + return 0; + } len = strlen(shift_name) - 1; shift_name[len] -= missing; seg_metalv(seg, s)->name = shift_name; /* Alter rimage name */ shift_name = dm_pool_strdup(cmd->mem, seg_lv(seg, s)->name); - if (!shift_name) - return_0; + if (!shift_name) { + log_error("Memory allocation failed."); + return 0; + } len = strlen(shift_name) - 1; shift_name[len] -= missing; seg_lv(seg, s)->name = shift_name; diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index ca609ee95..c8e6c7ff7 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -2356,6 +2356,9 @@ int dm_tree_node_add_raid_target(struct dm_tree_node *node, dm_segtypes[i].type, size))) return_0; + if (!seg) + return_0; + seg->region_size = region_size; seg->stripe_size = stripe_size; seg->area_count = 0;