You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found that cJSONUtils_SortObject(object) call if "object" is unsorted could break adding new fields to the object/array. It happens when the last field in the unsorted array/object becomes the first field.
In this case sorted object will have "object->child->prev" equal to 0 breaking the following assumption in the code
/* append to the end */
if (child->prev) <--------------------------- will be zero for sorted object
{
suffix_object(child->prev, item);
array->child->prev = item;
}
Another bad thing is that in this case we also have a memory leak since "item" variable is not assigned anywhere.
Moreover any API call from cJSON_Utils that is using sort_object() call internally also could break the input object. I am personally found it when debugging cJSONUtils_ApplyPatches().
I have found that cJSONUtils_SortObject(object) call if "object" is unsorted could break adding new fields to the object/array. It happens when the last field in the unsorted array/object becomes the first field.
In this case sorted object will have "object->child->prev" equal to 0 breaking the following assumption in the code
https://github.com/DaveGamble/cJSON/blob/master/cJSON.c#L2008
Another bad thing is that in this case we also have a memory leak since "item" variable is not assigned anywhere.
Moreover any API call from cJSON_Utils that is using sort_object() call internally also could break the input object. I am personally found it when debugging cJSONUtils_ApplyPatches().
Minimal example that reproduces the problem
Output of the program is
Note that "v3" field is missed in the final JSON.
The text was updated successfully, but these errors were encountered: