From cbdf514bbc3f22453c2c72c913e9161935a22bd8 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 7 May 2015 14:04:22 +0200 Subject: [PATCH] debug: extra validation of passed segment Always check if passed segment really is correct cache segment. (Avoids derefernce of possibly NULL seg->pool_lv). --- lib/cache_segtype/cache.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c index afc0ec64c..ca30495aa 100644 --- a/lib/cache_segtype/cache.c +++ b/lib/cache_segtype/cache.c @@ -282,9 +282,16 @@ static int _cache_add_target_line(struct dev_manager *dm, struct dm_tree_node *node, uint64_t len, uint32_t *pvmove_mirror_count __attribute__((unused))) { - struct lv_segment *cache_pool_seg = first_seg(seg->pool_lv); + struct lv_segment *cache_pool_seg; char *metadata_uuid, *data_uuid, *origin_uuid; + if (!seg->pool_lv || !seg_is_cache(seg)) { + log_error(INTERNAL_ERROR "Passed segment is not cache."); + return 0; + } + + cache_pool_seg = first_seg(seg->pool_lv); + if (!(metadata_uuid = build_dm_uuid(mem, cache_pool_seg->metadata_lv, NULL))) return_0;