Skip to content

Commit b175be2

Browse files
committed
Fix memory leak in rsa
1 parent 9051f24 commit b175be2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

openssl/openssl_evp.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ int _goboringcrypto_EVP_sign_raw(EVP_MD *md, EVP_PKEY_CTX *ctx, const uint8_t *m
4343
GO_RSA *rsa_key) {
4444
int ret = 0;
4545
GO_EVP_PKEY *pk = _goboringcrypto_EVP_PKEY_new();
46-
_goboringcrypto_EVP_PKEY_assign_RSA(pk, rsa_key);
46+
if (!pk)
47+
return 0;
48+
49+
if (!(_goboringcrypto_EVP_PKEY_set1_RSA(pk, rsa_key)))
50+
goto err;
4751

4852
if (!ctx && !(ctx = _goboringcrypto_EVP_PKEY_CTX_new(pk, NULL)))
4953
goto err;
@@ -63,6 +67,8 @@ int _goboringcrypto_EVP_sign_raw(EVP_MD *md, EVP_PKEY_CTX *ctx, const uint8_t *m
6367
err:
6468
if (ctx)
6569
_goboringcrypto_EVP_PKEY_CTX_free(ctx);
70+
if (pk)
71+
_goboringcrypto_EVP_PKEY_free(pk);
6672

6773
return ret;
6874
}
@@ -103,7 +109,11 @@ int _goboringcrypto_EVP_verify_raw(const uint8_t *msg, size_t msgLen,
103109
int ret = 0;
104110
EVP_PKEY_CTX *ctx;
105111
GO_EVP_PKEY *pk = _goboringcrypto_EVP_PKEY_new();
106-
_goboringcrypto_EVP_PKEY_assign_RSA(pk, rsa_key);
112+
if (!pk)
113+
return 0;
114+
115+
if (!(_goboringcrypto_EVP_PKEY_set1_RSA(pk, rsa_key)))
116+
goto err;
107117

108118
if (!(ctx = _goboringcrypto_EVP_PKEY_CTX_new(pk, NULL)))
109119
goto err;
@@ -123,6 +133,8 @@ int _goboringcrypto_EVP_verify_raw(const uint8_t *msg, size_t msgLen,
123133
err:
124134
if (ctx)
125135
_goboringcrypto_EVP_PKEY_CTX_free(ctx);
136+
if (pk)
137+
_goboringcrypto_EVP_PKEY_free(pk);
126138

127139
return ret;
128140
}

0 commit comments

Comments
 (0)