From 57af48d734f1f7aa985424a1e11287a0975077b9 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Thu, 18 Dec 2014 16:12:50 +0100 Subject: [PATCH] report: fix segfault on NULL value hit in cache_settings field We have to use empty list, not NULL if we want to denote that the list has no items. Otherwise, the code further can segfault as it expects there's always a sane value (= some list), including empty list, but never NULL. --- lib/report/report.c | 19 +++++++++++++++---- test/shell/lvs-cache.sh | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/report/report.c b/lib/report/report.c index 417396ca2..818e3fd2b 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -256,16 +256,27 @@ static int _cache_settings_disp(struct dm_report *rh, struct dm_pool *mem, const struct dm_config_node *settings; struct dm_list *result; struct _str_list_append_baton baton; + struct dm_list dummy_list; /* dummy list to display "nothing" */ if (seg_is_cache(seg)) seg = first_seg(seg->pool_lv); - else - return _field_set_value(field, "", NULL /* TODO: GET_FIRST_RESERVED_NAME(cache_settings_undef) */); + else { + dm_list_init(&dummy_list); + return _field_set_string_list(rh, field, &dummy_list, private, 0); + /* TODO: once we have support for STR_LIST reserved values, replace with: + * return _field_set_value(field, GET_FIRST_RESERVED_NAME(cache_settings_undef), GET_FIELD_RESERVED_VALUE(cache_settings_undef)); + */ + } if (seg->policy_settings) settings = seg->policy_settings->child; - else - return _field_set_value(field, "", NULL /* TODO: GET_FIRST_RESERVED_NAME(cache_settings_default) */); + else { + dm_list_init(&dummy_list); + return _field_set_string_list(rh, field, &dummy_list, private, 0); + /* TODO: once we have support for STR_LIST reserved values, replace with: + * return _field_set_value(field, GET_FIRST_RESERVED_NAME(cache_settings_undef), GET_FIELD_RESERVED_VALUE(cache_settings_undef)); + */ + } if (!(result = str_list_create(mem))) return_0; diff --git a/test/shell/lvs-cache.sh b/test/shell/lvs-cache.sh index 5108076bb..08e83bdad 100644 --- a/test/shell/lvs-cache.sh +++ b/test/shell/lvs-cache.sh @@ -58,6 +58,9 @@ lvs -o +cache_policy -S 'cache_policy=mq' | not grep foo lvs -o +cache_policy -S 'cache_policy=undefined' | not grep corigin lvs -o +cache_policy -S 'cache_policy=undefined' | grep foo lvs -o +cache_policy -O cache_policy +lvs -o +cache_settings -S 'cache_settings={migration_threshold=233}' | grep corigin +lvs -o +cache_settings -S 'cache_settings!={migration_threshold=233}' | grep foo +lvs -o +cache_policy -O cache_settings lvremove -f $vg