]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
array: Handle recursive calls to array_sort() if qsort_r() is not supported
authorTobias Brunner <tobias@strongswan.org>
Tue, 20 Jan 2026 09:58:01 +0000 (10:58 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 22 Jan 2026 17:14:58 +0000 (18:14 +0100)
Such a recursive call occurs when sorting the array of Child SAs inside
an IKE SA that causes comparisons of the child configs and their
proposals, which in turn creates a merged array of all transform types
and that uses array_sort() and array_bsearch().

Closes strongswan/strongswan#2926

Fixes: 8e7f379f716c ("ike-sa: Sort CHILD_SAs by CPU ID")
src/libstrongswan/collections/array.c

index 8b6c6d7397e22916e04946ae28de908d316273a5..0543ca24e616cc6c6996d3b3530fec8737f4fb63 100644 (file)
@@ -453,8 +453,12 @@ void array_sort(array_t *array, int (*cmp)(const void*,const void*,void*),
                qsort_r(start, array->count, get_size(array, 1), &data,
                                compare_elements);
 #else /* !HAVE_QSORT_R */
+               sort_data_t *recursive;
+
+               recursive = sort_data->get(sort_data);
                sort_data->set(sort_data, &data);
                qsort(start, array->count, get_size(array, 1), compare_elements);
+               sort_data->set(sort_data, recursive);
 #endif
        }
 }