Make WordPress Core

Changeset 53670


Ignore:
Timestamp:
07/06/2022 05:31:47 AM (3 years ago)
Author:
peterwilsoncc
Message:

Database: Ensure MySQL port numbers are numeric in wpdb.

Ensure the database port number is recorded as an integer or null (the default port) when parsing the database host.

This is to prevent PHP/MySQLi throwing an exception caused by ports represented as numeric strings.

Props audrasjb, azouamauriac, chaion07, costdev, johnjamesjacoby, jrf, sergeybiryukov.
Fixes #54877.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r53584 r53670  
    20772077            }
    20782078        }
     2079
     2080        // MySQLi port cannot be a string; must be null or an integer.
     2081        $port = $port ? absint( $port ) : null;
    20792082
    20802083        return array( $host, $port, $socket, $is_ipv6 );
  • trunk/tests/phpunit/tests/db.php

    r53577 r53670  
    19711971     * @dataProvider parse_db_host_data_provider
    19721972     * @ticket 41722
     1973     * @ticket 54877
    19731974     */
    19741975    public function test_parse_db_host( $host_string, $expect_bail, $host, $port, $socket, $is_ipv6 ) {
     
    20032004                false,
    20042005                '',
    2005                 '3306',
     2006                3306,
    20062007                null,
    20072008                false,
     
    20322033            ),
    20332034            array(
     2035                '127.0.0.1:port_as_string',
     2036                false,
     2037                '127.0.0.1',
     2038                null,
     2039                null,
     2040                false,
     2041            ),
     2042            array(
    20342043                '127.0.0.1:3306',
    20352044                false,
    20362045                '127.0.0.1',
    2037                 '3306',
     2046                3306,
    20382047                null,
    20392048                false,
     
    20432052                false,
    20442053                '127.0.0.1',
    2045                 '3306',
     2054                3306,
    20462055                '/tmp/mysql:with_colon.sock',
    20472056                false,
     
    20562065            ),
    20572066            array(
     2067                'example.com:port_as_string',
     2068                false,
     2069                'example.com',
     2070                null,
     2071                null,
     2072                false,
     2073            ),
     2074            array(
    20582075                'example.com:3306',
    20592076                false,
    20602077                'example.com',
    2061                 '3306',
     2078                3306,
    20622079                null,
    20632080                false,
     
    20722089            ),
    20732090            array(
     2091                'localhost:port_as_string',
     2092                false,
     2093                'localhost',
     2094                null,
     2095                null,
     2096                false,
     2097            ),
     2098            array(
    20742099                'localhost:/tmp/mysql.sock',
    20752100                false,
     
    20882113            ),
    20892114            array(
     2115                'localhost:port_as_string:/tmp/mysql:with_colon.sock',
     2116                false,
     2117                'localhost',
     2118                null,
     2119                '/tmp/mysql:with_colon.sock',
     2120                false,
     2121            ),
     2122            array(
    20902123                '0000:0000:0000:0000:0000:0000:0000:0001',
    20912124                false,
     
    21152148                false,
    21162149                '::1',
    2117                 '3306',
     2150                3306,
    21182151                null,
    21192152                true,
    21202153            ),
    21212154            array(
     2155                '[::1]:port_as_string',
     2156                false,
     2157                '::1',
     2158                null,
     2159                null,
     2160                true,
     2161            ),
     2162            array(
    21222163                '[::1]:3306:/tmp/mysql:with_colon.sock',
    21232164                false,
    21242165                '::1',
    2125                 '3306',
     2166                3306,
    21262167                '/tmp/mysql:with_colon.sock',
    21272168                true,
Note: See TracChangeset for help on using the changeset viewer.