]> git.kaiwu.me - quickjs.git/commitdiff
Check return values of fallible functions (#518)
authorbptato <60043228+bptato@users.noreply.github.com>
Thu, 4 Jun 2026 09:58:49 +0000 (11:58 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Jun 2026 09:58:49 +0000 (11:58 +0200)
Port of https://github.com/quickjs-ng/quickjs/pull/1409 (bnoordhuis).
I modified it to prevent an atom leak in js_parse_statement_or_decl,
otherwise it's the same.

quickjs.c

index 2e8b3da98ae7f66930eeac32ceba7bc6cf478a78..fa5a7a9d0181778042a97ddb7234aefc4a8fc9a8 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -28718,7 +28718,8 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
         int chunk_size = pos_expr - pos_next;
         int offset = bc->size - pos_next;
         int i;
-        dbuf_claim(bc, chunk_size);
+        if (dbuf_claim(bc, chunk_size))
+            return -1;
         dbuf_put(bc, bc->buf + pos_next, chunk_size);
         memset(bc->buf + pos_next, OP_nop, chunk_size);
         /* `next` part ends with a goto */
@@ -29124,7 +29125,8 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
                 int chunk_size = pos_body - pos_cont;
                 int offset = bc->size - pos_cont;
                 int i;
-                dbuf_claim(bc, chunk_size);
+                if (dbuf_claim(bc, chunk_size))
+                    goto fail;
                 dbuf_put(bc, bc->buf + pos_cont, chunk_size);
                 memset(bc->buf + pos_cont, OP_nop, chunk_size);
                 /* increment part ends with a goto */
@@ -38052,11 +38054,14 @@ static int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj)
     case JS_TAG_STRING_ROPE:
         {
             JSValue str;
+            int ret;
             str = JS_ToString(s->ctx, obj);
             if (JS_IsException(str))
                 goto fail;
-            JS_WriteObjectRec(s, str);
+            ret = JS_WriteObjectRec(s, str);
             JS_FreeValue(s->ctx, str);
+            if (ret)
+                goto fail;
         }
         break;
     case JS_TAG_FUNCTION_BYTECODE: