Previously, when EVP_PKEY_derive() succeeded but returned fewer bytes
than requested, HKDF deriveBits() and deriveKey() set an exception but
the shared cleanup only checked the positive OpenSSL return value.
The operation then resolved with partially initialized output.
Mark the result as failed before jumping to the cleanup.
The issue was introduced in
7b2b7612 (0.7.0) and copied to QuickJS
in
75ca26f8 (0.8.10).
ret = EVP_PKEY_derive(pctx, k, &olen);
if (njs_slow_path(ret <= 0 || olen != (size_t) length)) {
njs_webcrypto_error(vm, "EVP_PKEY_derive() failed");
+ ret = NJS_ERROR;
goto free;
}
rc = EVP_PKEY_derive(pctx, k, &olen);
if (rc <= 0 || olen != (size_t) length) {
qjs_webcrypto_error(cx, "EVP_PKEY_derive() failed");
+ rc = -1;
goto free;
}