]> granicus.if.org Git - php/commitdiff
Make mysqli_connect arguments explicitly nullable
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 5 Jun 2019 09:26:20 +0000 (11:26 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 5 Jun 2019 09:30:13 +0000 (11:30 +0200)
It should be possible to skip any of these (and use the ini configured
defaults) by passing null, independently of strict_types settings.

Noticed while working on GH-4227.

ext/mysqli/mysqli_nonapi.c

index 3ffa8d05ddb59775aa9975275ddda7713a049ad6..d6c474b7f39e14405918678f821899eab5d2c3e9 100644 (file)
@@ -58,6 +58,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
        size_t                                  hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
        zend_bool                       persistent = FALSE;
        zend_long                               port = 0, flags = 0;
+       zend_bool port_is_null = 1;
        zend_string                     *hash_key = NULL;
        zend_bool                       new_connection = FALSE;
        zend_resource           *le;
@@ -80,8 +81,8 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
        hostname = username = dbname = passwd = socket = NULL;
 
        if (!is_real_connect) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ssssls", &hostname, &hostname_len, &username, &username_len,
-                                                                       &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!s!l!s!", &hostname, &hostname_len, &username, &username_len,
+                               &passwd, &passwd_len, &dbname, &dbname_len, &port, &port_is_null, &socket, &socket_len) == FAILURE) {
                        return;
                }
 
@@ -98,9 +99,8 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
                flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
        } else {
                /* We have flags too */
-               if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|sssslsl", &object, mysqli_link_class_entry,
-                                                                               &hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len,
-                                                                               &flags) == FAILURE) {
+               if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|s!s!s!s!l!s!l", &object, mysqli_link_class_entry,
+                               &hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &port_is_null, &socket, &socket_len, &flags) == FAILURE) {
                        return;
                }
 
@@ -121,7 +121,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
        if (!socket_len || !socket) {
                socket = MyG(default_socket);
        }
-       if (!port){
+       if (port_is_null || !port) {
                port = MyG(default_port);
        }
        if (!passwd) {