]> git.kaiwu.me - njs.git/commitdiff
WebCrypto: avoid freeing RSA JWK values twice
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 16 Nov 2026 23:35:46 +0000 (15:35 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 17 Nov 2026 22:09:33 +0000 (14:09 -0800)
Previously, RSA JWK import released its parameter values before
creating the EVP_PKEY.  A failure in EVP_PKEY_new() or
EVP_PKEY_set1_RSA() then released the same values in error cleanup.

Reset released values so the error handler no longer owns them.
The issue was introduced in 75ca26f8 (0.8.10).

external/qjs_webcrypto_module.c

index f4b22b699f6e9007275044a3ba1ae8ef638d50e0..399eac1fd8118b827104f6b831e67ba12d81f069 100644 (file)
@@ -3360,12 +3360,20 @@ fail1:
     JS_FreeValue(cx, dp);
     JS_FreeValue(cx, dq);
     JS_FreeValue(cx, qi);
+    p = JS_UNDEFINED;
+    q = JS_UNDEFINED;
+    dp = JS_UNDEFINED;
+    dq = JS_UNDEFINED;
+    qi = JS_UNDEFINED;
 
 done:
 
     JS_FreeValue(cx, n);
     JS_FreeValue(cx, e);
     JS_FreeValue(cx, d);
+    n = JS_UNDEFINED;
+    e = JS_UNDEFINED;
+    d = JS_UNDEFINED;
 
     pkey = EVP_PKEY_new();
     if (pkey == NULL) {