Skip to content

Commit 0afdf19

Browse files
committed
1 parent efbc962 commit 0afdf19

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub
809809
*/
810810
if ((size_t) server_public_key_len <= passwd_len + 41) {
811811
/* password message is to long */
812+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
812813
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
813814
DBG_ERR("password is too long");
814815
DBG_RETURN(0);
@@ -818,6 +819,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub
818819
ret = malloc(*auth_data_len);
819820
if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info,
820821
NULL, 0, ret, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) {
822+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
821823
DBG_RETURN(0);
822824
}
823825
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
@@ -1057,6 +1059,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv
10571059
*/
10581060
if ((size_t) server_public_key_len <= passwd_len + 41) {
10591061
/* password message is to long */
1062+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
10601063
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
10611064
DBG_ERR("password is too long");
10621065
DBG_RETURN(0);
@@ -1065,8 +1068,10 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv
10651068
*crypted = emalloc(server_public_key_len);
10661069
if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info,
10671070
NULL, 0, *crypted, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) {
1071+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
10681072
DBG_RETURN(0);
10691073
}
1074+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
10701075
DBG_RETURN(server_public_key_len);
10711076
}
10721077
/* }}} */

0 commit comments

Comments
 (0)