Skip to content

Commit 52bfcaf

Browse files
authored
tls: pop errors from failed session parsing
Signed-off-by: lazerg <lazerg2@gmail.com> PR-URL: #67212 Fixes: #67204 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7996b18 commit 52bfcaf

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/crypto/crypto_common.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace node {
3030
using ncrypto::ClearErrorOnReturn;
3131
using ncrypto::EVPKeyPointer;
3232
using ncrypto::KeyAlgorithm;
33+
using ncrypto::MarkPopErrorOnReturn;
3334
using ncrypto::SSLPointer;
3435
using ncrypto::SSLSessionPointer;
3536
using ncrypto::StackOfX509;
@@ -49,6 +50,7 @@ using v8::Value;
4950
namespace crypto {
5051

5152
SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) {
53+
MarkPopErrorOnReturn mark_pop_error_on_return;
5254
return SSLSessionPointer(d2i_SSL_SESSION(nullptr, &buf, length));
5355
}
5456

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const crypto = require('crypto');
9+
const tls = require('tls');
10+
11+
// A session that fails to deserialize must not leave an error on the OpenSSL
12+
// error queue for the next unrelated crypto operation to pick up.
13+
14+
const badKey = '-----BEGIN PRIVATE KEY-----\nAAAA\n-----END PRIVATE KEY-----';
15+
16+
function keyErrorCode() {
17+
try {
18+
crypto.createPrivateKey(badKey);
19+
} catch (err) {
20+
return err.code;
21+
}
22+
assert.fail('createPrivateKey() should have thrown');
23+
}
24+
25+
const expected = keyErrorCode();
26+
new tls.TLSSocket(null, { session: Buffer.from('invalid session') });
27+
assert.strictEqual(keyErrorCode(), expected);

0 commit comments

Comments
 (0)