mirror of
https://github.com/libretro/libretro-common.git
synced 2026-11-07 11:06:12 -10:00
linked_list: guard remove_*_matching against NULL matches callback (#234)
linked_list_remove_first_matching(), linked_list_remove_last_matching(), and linked_list_remove_all_matching() dereferenced a NULL matches callback on a non-empty list, unlike the lookup functions which already guard against this. Add the same !list || !matches check used by linked_list_get_first_matching() and linked_list_get_last_matching(). Adds a NULL-callback test case for each of the three functions. Fixes #232
This commit is contained in:
1 parent
9863d6937a
commit
6da1b7eefb
2 files changed
+30
-3
No files matched your search
+3
-3
@@ -303,7 +303,7 @@ void *linked_list_remove_first_matching(linked_list_t *list, bool (*matches)(voi
|
||||
{
|
||||
struct linked_list_item_t *item;
|
||||
|
||||
if (!list)
|
||||
if (!list || !matches)
|
||||
return NULL;
|
||||
|
||||
for (item = list->first_item; item; item = item->next)
|
||||
@@ -328,7 +328,7 @@ void *linked_list_remove_last_matching(linked_list_t *list, bool (*matches)(void
|
||||
{
|
||||
struct linked_list_item_t *item;
|
||||
|
||||
if (!list)
|
||||
if (!list || !matches)
|
||||
return NULL;
|
||||
|
||||
for (item = list->last_item; item; item = item->previous)
|
||||
@@ -353,7 +353,7 @@ void linked_list_remove_all_matching(linked_list_t *list, bool (*matches)(void *
|
||||
{
|
||||
struct linked_list_item_t *item;
|
||||
|
||||
if (!list)
|
||||
if (!list || !matches)
|
||||
return;
|
||||
|
||||
for (item = list->first_item; item;)
|
||||
|
||||
@@ -695,6 +695,13 @@ START_TEST (test_linked_list_remove_first_matching_null)
|
||||
ck_assert_ptr_null(linked_list_remove_first_matching(NULL, &_match_value_1));
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_linked_list_remove_first_matching_function_null)
|
||||
{
|
||||
linked_list_t *list = linked_list_new();
|
||||
ck_assert_ptr_null(linked_list_remove_first_matching(list, NULL));
|
||||
|
||||
linked_list_free(list, NULL);
|
||||
}
|
||||
|
||||
START_TEST (test_linked_list_remove_first_matching_empty)
|
||||
{
|
||||
@@ -798,6 +805,14 @@ START_TEST (test_linked_list_remove_last_matching_null)
|
||||
ck_assert_ptr_null(linked_list_remove_last_matching(NULL, &_match_value_1));
|
||||
}
|
||||
END_TEST
|
||||
START_TEST (test_linked_list_remove_last_matching_function_null)
|
||||
{
|
||||
linked_list_t *list = linked_list_new();
|
||||
ck_assert_ptr_null(linked_list_remove_last_matching(list, NULL));
|
||||
|
||||
linked_list_free(list, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_linked_list_remove_last_matching_empty)
|
||||
{
|
||||
@@ -902,6 +917,15 @@ START_TEST (test_linked_list_remove_all_matching_null)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_linked_list_remove_all_matching_function_null)
|
||||
{
|
||||
linked_list_t *list = linked_list_new();
|
||||
linked_list_remove_all_matching(list, NULL);
|
||||
|
||||
linked_list_free(list, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_linked_list_remove_all_matching_empty)
|
||||
{
|
||||
linked_list_t *list = linked_list_new();
|
||||
@@ -1246,6 +1270,7 @@ Suite *create_suite(void)
|
||||
tcase_add_test(tc_core, test_linked_list_remove_all_only);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_all_multiple);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_null);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_function_null);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_empty);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_not_found);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_first);
|
||||
@@ -1254,7 +1279,9 @@ Suite *create_suite(void)
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_only);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_first_matching_multiple);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_last_matching_null);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_all_matching_function_null);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_last_matching_empty);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_last_matching_function_null);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_last_matching_not_found);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_last_matching_first);
|
||||
tcase_add_test(tc_core, test_linked_list_remove_last_matching_middle);
|
||||
|
||||
Reference in new issue
Block a user