]> git.kaiwu.me - njs.git/commitdiff
WebCrypto: avoid freeing njs signing contexts twice
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Nov 2026 20:35:33 +0000 (12:35 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 17 Nov 2026 22:09:33 +0000 (14:09 -0800)
Previously, sign() and verify() for RSA and ECDSA freed the digest
and key contexts at verify_done without resetting the pointers.  If
creating the resulting ArrayBuffer then failed, the error path freed
both contexts again.

Reset the pointers after freeing, as the QuickJS implementation does.

The issue was introduced in 50e7c9b2 (0.7.10).

external/njs_webcrypto_module.c

index 9187898bef152bdbe59af7a920d4261708356ec2..23d0b96dd60773418a7a2f260de3743ff1ca8865 100644 (file)
@@ -4965,8 +4965,10 @@ njs_ext_sign(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     verify_done:
 
         njs_evp_md_ctx_free(mctx);
+        mctx = NULL;
 
         EVP_PKEY_CTX_free(pctx);
+        pctx = NULL;
 
         break;
     }