Fix use-after-free in args2obj() array argument path (#3498)

Copy `kk` and `vk` before passing to jv_object_get(), which consumes
its arguments. Without copies, subsequent loop iterations read freed
memory (CWE-416) and post-loop jv_free() double-frees (CWE-415).

This bug was introduced in `b279713e` when array processing was hoisted
out of
the loop into locals without accounting for jv_object_get() semantics.
Fixes GHSA-gf4g-95wj-4q4r.
This commit is contained in:
Scott Seal authored and GitHub committed 2026-03-09 17:30:08 +09:00
1 parent 3cd7e0da00
commit 3985b80ce5
2 files changed
+188 -1

No files matched your search

+1 -1
View File
@@ -1222,7 +1222,7 @@ args2obj(jv args)
jv kk = jv_string("name");
jv vk = jv_string("value");
jv_array_foreach(args, i, v)
r = jv_object_set(r, jv_object_get(jv_copy(v), kk), jv_object_get(v, vk));
r = jv_object_set(r, jv_object_get(jv_copy(v), jv_copy(kk)), jv_object_get(v, jv_copy(vk)));
jv_free(args);
jv_free(kk);
jv_free(vk);