Skip to content

Commit 42f0945

Browse files
bptatosaghul
authored andcommitted
Fix NULL deref in JS_NewRuntime2
The API allows for the malloc_usable_size callback to be NULL, so it must not be dereferenced before the NULL check.
1 parent 284510f commit 42f0945

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

quickjs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,14 +1795,14 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
17951795
rt = mf->js_calloc(opaque, 1, sizeof(JSRuntime));
17961796
if (!rt)
17971797
return NULL;
1798-
/* Inline what js_malloc_rt does since we cannot use it here. */
1799-
ms.malloc_count++;
1800-
ms.malloc_size += mf->js_malloc_usable_size(rt) + MALLOC_OVERHEAD;
18011798
rt->mf = *mf;
18021799
if (!rt->mf.js_malloc_usable_size) {
18031800
/* use dummy function if none provided */
18041801
rt->mf.js_malloc_usable_size = js_malloc_usable_size_unknown;
18051802
}
1803+
/* Inline what js_malloc_rt does since we cannot use it here. */
1804+
ms.malloc_count++;
1805+
ms.malloc_size += rt->mf.js_malloc_usable_size(rt) + MALLOC_OVERHEAD;
18061806
rt->malloc_state = ms;
18071807
rt->malloc_gc_threshold = 256 * 1024;
18081808

0 commit comments

Comments
 (0)