]> git.kaiwu.me - njs.git/commit
Fixed Array.prototype.join() when array is changed while iterating.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 12 Jan 2022 17:59:42 +0000 (17:59 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 12 Jan 2022 17:59:42 +0000 (17:59 +0000)
commite00eac3d6080d39b414f366d88c7dc167f082055
tree47eb991174d9628ae1ef911000edae0b6af3a6cc
parentd225ff9cc157862fa2f69824b713ee7352c538f2
Fixed Array.prototype.join() when array is changed while iterating.

Previously, the function used optimization for ordinary arrays with no
gaps (so called fast arrays).  For a fast array code took elements
directly from internal flat C array. The direct pointer may become
invalid as side-effect of custom toString() method for an element.

Specifically, the pointer was passed directly to
njs_value_to_primitive() which attempts to call toString() followed by
valueOf().  When the array size is changed as a side-effect of
toString() and not a string value is returned by toString() the pointer
becomes invalid and is passed to valueOf() which causes use-after-free.

The fix is to eliminate the micro-optimization which uses direct pointers.

Found by PolyGlot fuzzing framework.

This closes #444 issue on Github.
src/njs_array.c
src/test/njs_unit_test.c