about summary refs log tree commit diff stats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-20 23:34:05 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-20 23:35:24 +0100
commit5e4e35899029c91597ac78eb27be488fdcd7f69b (patch)
tree5c955e6c5730aa86068a8eb63c3ebbd1395f963b /src/js
parent2b60e1009f54ef8d09bf66b092a613840e9ec59b (diff)
downloadchawan-5e4e35899029c91597ac78eb27be488fdcd7f69b.tar.gz
js: fix nil deref in jsgetprop
Turns out desc can in fact be nil.
Diffstat (limited to 'src/js')
-rw-r--r--src/js/javascript.nim13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 8f7f445c..78999668 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -946,10 +946,15 @@ macro jsgetprop*(fun: typed) =
     block `dl`:
       let retv = ctx.toJS(`jfcl`)
       if retv != JS_NULL:
-        desc[].setter = JS_UNDEFINED
-        desc[].getter = JS_UNDEFINED
-        desc[].value = retv
-        desc[].flags = 0
+        if desc != nil:
+          # From quickjs.h:
+          # > If 1 is returned, the property descriptor 'desc' is filled
+          # > if != NULL.
+          # So desc may be nil.
+          desc[].setter = JS_UNDEFINED
+          desc[].getter = JS_UNDEFINED
+          desc[].value = retv
+          desc[].flags = 0
         return cint(1)
     return cint(0)
   let jsProc = gen.newJSProc(getJSGetPropParams(), false)