]> git.kaiwu.me - njs.git/commit
Fix use-after-free in Array.prototype.sort()
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 10 Jun 2026 21:52:23 +0000 (14:52 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 15 Jun 2026 23:50:15 +0000 (16:50 -0700)
commit9bdc3098f49398039b5fd63579d4380c52a665e5
treeb54916a31833f9d85011aa84230c1a44de23f270
parent241dffa95d8ec2b237b1cf19eb105e0a824874fc
Fix use-after-free in Array.prototype.sort()

Previously, njs_sort_indexed_properties() cached the fast array backing
store pointer (array->start) once and then iterates.  For a hole it
performed a generic property lookup that walks the prototype chain and
may invoke a user-defined getter.  A getter that grows the same array
triggers njs_array_expand(), which reallocates the backing store and
frees the old buffer, leaving the cached pointer dangling.  The
remaining iterations then read freed memory, and the stale values are
sorted and written back, exposing freed heap contents to script.

Reported by Sangsoo Jeong (78ResearchLab).
src/njs_array.c
src/test/njs_unit_test.c