Skip to content

Commit b871261

Browse files
andr3y-k0v4l3vAndrey Kovalev
and
Andrey Kovalev
authored
ext/mysqlnd/mysqlnd_auth.c: Add error handling for invalid public key size (#18663)
Reported-by: Pavel Nekrasov <[email protected]> Signed-off-by: Andrey Kovalev <[email protected]> Co-authored-by: Andrey Kovalev <[email protected]>
1 parent f64e3d5 commit b871261

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,19 @@ void php_mysqlnd_scramble_sha2(zend_uchar * const buffer, const zend_uchar * con
10051005
static size_t
10061006
mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_public_key, size_t passwd_len, unsigned char **crypted, char *xor_str)
10071007
{
1008-
size_t server_public_key_len = (size_t) EVP_PKEY_size(server_public_key);
1009-
10101008
DBG_ENTER("mysqlnd_caching_sha2_public_encrypt");
1009+
1010+
int pkey_size = EVP_PKEY_size(server_public_key);
1011+
1012+
if (pkey_size <= 0) {
1013+
EVP_PKEY_free(server_public_key);
1014+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "invalid public key size");
1015+
DBG_ERR("invalid public key size");
1016+
DBG_RETURN(0);
1017+
}
1018+
1019+
size_t server_public_key_len = (size_t) pkey_size;
1020+
10111021
/*
10121022
Because RSA_PKCS1_OAEP_PADDING is used there is a restriction on the passwd_len.
10131023
RSA_PKCS1_OAEP_PADDING is recommended for new applications. See more here:

0 commit comments

Comments
 (0)