From: Dmitry Volyntsev Date: Tue, 9 Jan 2024 17:14:42 +0000 (-0800) Subject: Avoiding arithmetic ops with NULL in %TypedArray%.prototype.sort(). X-Git-Tag: 0.8.3~18 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=d3a5589379055a9fd10a3fabf6a64f92d95d2f72;p=njs.git Avoiding arithmetic ops with NULL in %TypedArray%.prototype.sort(). Found by UndefinedBehaviorSanitizer. --- diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c index 7b0abc63..c483ff52 100644 --- a/src/njs_typed_array.c +++ b/src/njs_typed_array.c @@ -2035,6 +2035,11 @@ njs_typed_array_prototype_sort(njs_vm_t *vm, njs_value_t *args, } njs_qsort(base, length, element_size, cmp, &ctx); + + if (njs_slow_path(ctx.exception)) { + return NJS_ERROR; + } + if (ctx.function != NULL) { if (&buffer->u.u8[array->offset * element_size] == orig) { memcpy(orig, base, length * element_size); @@ -2043,10 +2048,6 @@ njs_typed_array_prototype_sort(njs_vm_t *vm, njs_value_t *args, njs_mp_free(vm->mem_pool, base); } - if (njs_slow_path(ctx.exception)) { - return NJS_ERROR; - } - njs_set_typed_array(retval, array); return NJS_OK;