Skip to content

Commit 3b26a38

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix leak on Windows as well
2 parents d963b78 + 0afdf19 commit 3b26a38

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
@@ -807,6 +807,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub
807807
*/
808808
if ((size_t) server_public_key_len <= passwd_len + 41) {
809809
/* password message is to long */
810+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
810811
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
811812
DBG_ERR("password is too long");
812813
DBG_RETURN(0);
@@ -816,6 +817,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub
816817
ret = malloc(*auth_data_len);
817818
if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info,
818819
NULL, 0, ret, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) {
820+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
819821
DBG_RETURN(0);
820822
}
821823
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
@@ -1055,6 +1057,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv
10551057
*/
10561058
if ((size_t) server_public_key_len <= passwd_len + 41) {
10571059
/* password message is to long */
1060+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
10581061
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
10591062
DBG_ERR("password is too long");
10601063
DBG_RETURN(0);
@@ -1063,8 +1066,10 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv
10631066
*crypted = emalloc(server_public_key_len);
10641067
if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info,
10651068
NULL, 0, *crypted, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) {
1069+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
10661070
DBG_RETURN(0);
10671071
}
1072+
BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key);
10681073
DBG_RETURN(server_public_key_len);
10691074
}
10701075
/* }}} */

0 commit comments

Comments
 (0)