From de0eb9d72a500478b587f37f695b510da4f20de0 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 18 Dec 2018 17:19:02 +0100 Subject: [PATCH] loader: check for null pointer in getArray() and getString() --- lib/loader/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/loader/index.js b/lib/loader/index.js index 7f79027bdb..1f893c039e 100644 --- a/lib/loader/index.js +++ b/lib/loader/index.js @@ -80,6 +80,11 @@ function postInstantiate(baseModule, instance) { } checkMem(); + /** Raises an exception if a pointer is the NULL pointer. */ + function checkNull(ptr) { + if (!ptr) throw Error("null pointer deref"); + } + /** Allocates a new string in the module's memory and returns its pointer. */ function newString(str) { var dataLength = str.length; @@ -96,6 +101,7 @@ function postInstantiate(baseModule, instance) { /** Gets a string from the module's memory by its pointer. */ function getString(ptr) { checkMem(); + checkNull(ptr); return getStringImpl(U32, U16, ptr); } @@ -145,6 +151,7 @@ function postInstantiate(baseModule, instance) { var elementSize = ctor.BYTES_PER_ELEMENT; if (!elementSize) throw Error("not a typed array"); checkMem(); + checkNull(ptr); var buf = U32[ ptr >>> 2]; var byteOffset = U32[(ptr + 4) >>> 2]; var byteLength = U32[(ptr + 8) >>> 2];