Skip to content

Commit 3cc8fca

Browse files
bnoordhuistargos
authored andcommitted
crypto: handle i2d_SSL_SESSION() error return
i2d_SSL_SESSION() can return a value <= 0 when the session is malformed or otherwise invalid. Handle that case. This change comes without a regression test because I couldn't figure out a good way to generate an existing but invalid session in a timely fashion. Fixes: #29202 PR-URL: #29225 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ff6330a commit 3cc8fca

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/node_crypto.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -2317,11 +2317,12 @@ void SSLWrap<Base>::GetSession(const FunctionCallbackInfo<Value>& args) {
23172317
return;
23182318

23192319
int slen = i2d_SSL_SESSION(sess, nullptr);
2320-
CHECK_GT(slen, 0);
2320+
if (slen <= 0)
2321+
return; // Invalid or malformed session.
23212322

23222323
AllocatedBuffer sbuf = env->AllocateManaged(slen);
23232324
unsigned char* p = reinterpret_cast<unsigned char*>(sbuf.data());
2324-
i2d_SSL_SESSION(sess, &p);
2325+
CHECK_LT(0, i2d_SSL_SESSION(sess, &p));
23252326
args.GetReturnValue().Set(sbuf.ToBuffer().ToLocalChecked());
23262327
}
23272328

0 commit comments

Comments
 (0)