1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Peter Rajnoha 2014-12-18 16:12:50 +01:00
parent da9da0d8c2
commit 57af48d734
2 changed files with 18 additions and 4 deletions

View File

@ -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;

View File

@ -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