From d53e6f32e7917e66b689c88ab0a660ea3e6e2d8f Mon Sep 17 00:00:00 2001 From: Bence Szigeti Date: Fri, 10 Nov 2023 12:55:46 +0100 Subject: [PATCH] json: fix array element deletion OpenSIPS incorrectly calls the JSON-C array element deletion function by passing the size of the array instead of the desired count of elements to delete. When attempting to delete from index `0`, it results in the deletion of all elements, while specifying an index greater than `0` leads to no deletion due to overindexing. ### Example 1: ``` $json(obj) := "[ 1, 2, 3 ]"; $json(obj[0]) = NULL; xlog("$json(obj)\n"); ``` Result: `[]` Expected: `[ 2, 3 ]` ### Example 2: ``` $json(obj) := "[ 1, 2, 3 ]"; $json(obj[1]) = NULL; xlog("$json(obj)\n"); ``` Result: `[ 1, 2, 3 ]` Expected: `[ 1, 3 ]` --- modules/json/array_del.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/json/array_del.c b/modules/json/array_del.c index 9ec0030ccc8..10e211eb554 100644 --- a/modules/json/array_del.c +++ b/modules/json/array_del.c @@ -31,8 +31,7 @@ void json_object_array_del(struct json_object* obj, int idx) { #if JSON_C_VERSION_NUM >= JSON_C_VERSION_013 - array_list_del_idx(json_object_get_array(obj), idx, - json_object_get_array(obj)->length); + array_list_del_idx(json_object_get_array(obj), idx, 1); #else if(idx >= obj->o.c_array->length) return;