Skip to content

Commit fb38a1c

Browse files
ndosschematzbot
authored andcommitted
[ruby/openssl] pkey: fix memory leak when derived key is too large
Unlikely to happen in practice, but mirrors other similar checks that also free the context. ruby/openssl@fd28a16519
1 parent 11e3c78 commit fb38a1c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

ext/openssl/ossl_pkey.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,8 +1496,10 @@ ossl_pkey_derive(int argc, VALUE *argv, VALUE self)
14961496
EVP_PKEY_CTX_free(ctx);
14971497
ossl_raise(ePKeyError, "EVP_PKEY_derive");
14981498
}
1499-
if (keylen > LONG_MAX)
1499+
if (keylen > LONG_MAX) {
1500+
EVP_PKEY_CTX_free(ctx);
15001501
rb_raise(ePKeyError, "derived key would be too large");
1502+
}
15011503
str = ossl_str_new(NULL, (long)keylen, &state);
15021504
if (state) {
15031505
EVP_PKEY_CTX_free(ctx);

0 commit comments

Comments
 (0)