Skip to content

tls: fix error stack conversion in cryptoErrorListToException() #56554

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ MaybeLocal<Value> cryptoErrorListToException(
if (errors.size() > 1) {
CHECK(exception->IsObject());
Local<Object> exception_obj = exception.As<Object>();
LocalVector<Value> stack(env->isolate(), errors.size() - 1);
LocalVector<Value> stack(env->isolate());
stack.reserve(errors.size() - 1);

// Iterate over all but the last error in the list.
auto current = errors.begin();
Expand All @@ -255,9 +256,9 @@ MaybeLocal<Value> cryptoErrorListToException(
Local<v8::Array> stackArray =
v8::Array::New(env->isolate(), stack.data(), stack.size());

if (!exception_obj
->Set(env->context(), env->openssl_error_stack(), stackArray)
.IsNothing()) {
if (exception_obj
->Set(env->context(), env->openssl_error_stack(), stackArray)
.IsNothing()) {
return {};
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-tls-error-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

// This tests that the crypto error stack can be correctly converted.
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const tls = require('tls');

assert.throws(() => {
tls.createSecureContext({ clientCertEngine: 'x' });
}, (err) => {
return err.name === 'Error' &&
/could not load the shared library/.test(err.message) &&
Array.isArray(err.opensslErrorStack) &&
err.opensslErrorStack.length > 0;
});
Loading