]> granicus.if.org Git - php/commitdiff
Fix RSA memory leak in mysqlnd auth
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 23 Mar 2020 10:54:55 +0000 (11:54 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 23 Mar 2020 10:55:22 +0000 (11:55 +0100)
ext/mysqlnd/mysqlnd_auth.c

index fa156fa0e1fb66107b9e2ea5253618289a8d30e0..fa8c709516420614653282df226747cb29f8d958 100644 (file)
@@ -728,6 +728,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub
        */
        if (server_public_key_len <= passwd_len + 41) {
                /* password message is to long */
+               RSA_free(server_public_key);
                SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
                DBG_ERR("password is too long");
                DBG_RETURN(NULL);
@@ -1018,6 +1019,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv
        */
        if (server_public_key_len <= passwd_len + 41) {
                /* password message is to long */
+               RSA_free(server_public_key);
                SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
                DBG_ERR("password is too long");
                DBG_RETURN(0);
@@ -1025,6 +1027,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv
 
        *crypted = emalloc(server_public_key_len);
        RSA_public_encrypt(passwd_len + 1, (zend_uchar *) xor_str, *crypted, server_public_key, RSA_PKCS1_OAEP_PADDING);
+       RSA_free(server_public_key);
        DBG_RETURN(server_public_key_len);
 }
 /* }}} */