From: Ilia Alshanetsky Date: Thu, 20 Dec 2007 00:31:49 +0000 (+0000) Subject: MFB: Fixed bug #43635 (mysql extension ingores INI settings on NULL values X-Git-Tag: php-5.2.6RC1~232 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c21ef044a7823760fd7f952594d5f66a3355f7e0;p=php MFB: Fixed bug #43635 (mysql extension ingores INI settings on NULL values passed to mysql_connect()) --- diff --git a/NEWS b/NEWS index b637b969a0..5246b7f1d5 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2008, PHP 5.2.6 - Fixed weired behavior in CGI parameter parsing. (Dmitry, Hannes Magnusson) +- Fixed bug #43635 (mysql extension ingores INI settings on NULL values + passed to mysql_connect()). (Ilia) - Fixed bug #43620 (Workaround for a bug inside libcurl 7.16.2 that can result in a crash). (Ilia) - Fixed bug #43606 (define missing depencies of the exif extension). diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 8675624a04..81f091ee9f 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -514,6 +514,7 @@ PHP_MINFO_FUNCTION(mysql) static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) { char *user=NULL, *passwd=NULL, *host_and_port=NULL, *socket=NULL, *tmp=NULL, *host=NULL; + int user_len, passwd_len, host_len; char *hashed_details=NULL; int hashed_details_length, port = MYSQL_PORT; int client_flags = 0; @@ -521,7 +522,6 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) #if MYSQL_VERSION_ID <= 32230 void (*handler) (int); #endif - zval **z_host=NULL, **z_user=NULL, **z_passwd=NULL, **z_new_link=NULL, **z_client_flags=NULL; zend_bool free_host=0, new_link=0; long connect_timeout; @@ -556,99 +556,32 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) hashed_details_length = spprintf(&hashed_details, 0, "mysql__%s_", user); client_flags = CLIENT_INTERACTIVE; } else { - host_and_port = MySG(default_host); - user = MySG(default_user); - passwd = MySG(default_password); - - switch(ZEND_NUM_ARGS()) { - case 0: /* defaults */ - break; - case 1: { - if (zend_get_parameters_ex(1, &z_host)==FAILURE) { - MYSQL_DO_CONNECT_RETURN_FALSE(); - } - } - break; - case 2: { - if (zend_get_parameters_ex(2, &z_host, &z_user)==FAILURE) { - MYSQL_DO_CONNECT_RETURN_FALSE(); - } - convert_to_string_ex(z_user); - user = Z_STRVAL_PP(z_user); - } - break; - case 3: { - if (zend_get_parameters_ex(3, &z_host, &z_user, &z_passwd) == FAILURE) { - MYSQL_DO_CONNECT_RETURN_FALSE(); - } - convert_to_string_ex(z_user); - convert_to_string_ex(z_passwd); - user = Z_STRVAL_PP(z_user); - passwd = Z_STRVAL_PP(z_passwd); - } - break; - case 4: { - if (!persistent) { - if (zend_get_parameters_ex(4, &z_host, &z_user, &z_passwd, &z_new_link) == FAILURE) { - MYSQL_DO_CONNECT_RETURN_FALSE(); - } - convert_to_string_ex(z_user); - convert_to_string_ex(z_passwd); - convert_to_boolean_ex(z_new_link); - user = Z_STRVAL_PP(z_user); - passwd = Z_STRVAL_PP(z_passwd); - new_link = Z_BVAL_PP(z_new_link); - } - else { - if (zend_get_parameters_ex(4, &z_host, &z_user, &z_passwd, &z_client_flags) == FAILURE) { - MYSQL_DO_CONNECT_RETURN_FALSE(); - } - convert_to_string_ex(z_user); - convert_to_string_ex(z_passwd); - convert_to_long_ex(z_client_flags); - user = Z_STRVAL_PP(z_user); - passwd = Z_STRVAL_PP(z_passwd); - client_flags = Z_LVAL_PP(z_client_flags); - } - } - break; - case 5: { - if (zend_get_parameters_ex(5, &z_host, &z_user, &z_passwd, &z_new_link, &z_client_flags) == FAILURE) { - MYSQL_DO_CONNECT_RETURN_FALSE(); - } - convert_to_string_ex(z_user); - convert_to_string_ex(z_passwd); - convert_to_boolean_ex(z_new_link); - convert_to_long_ex(z_client_flags); - user = Z_STRVAL_PP(z_user); - passwd = Z_STRVAL_PP(z_passwd); - new_link = Z_BVAL_PP(z_new_link); - client_flags = Z_LVAL_PP(z_client_flags); - } - break; - default: - WRONG_PARAM_COUNT; - break; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!ll", &host_and_port, &host_len, + &user, &user_len, &passwd, &passwd_len, + &new_link, &client_flags)==FAILURE) { + WRONG_PARAM_COUNT; + } + + if (!host_and_port) { + host_and_port = MySG(default_host); + } + if (!user) { + user = MySG(default_user); } + if (!passwd) { + passwd = MySG(default_password); + } + + /* mysql_pconnect does not support new_link parameter */ + if (persistent) { + client_flags= new_link; + } + /* disable local infile option for open_basedir */ if (((PG(open_basedir) && PG(open_basedir)[0] != '\0') || PG(safe_mode)) && (client_flags & CLIENT_LOCAL_FILES)) { client_flags ^= CLIENT_LOCAL_FILES; } - if (z_host) { - SEPARATE_ZVAL(z_host); /* We may modify z_host if it contains a port, separate */ - convert_to_string_ex(z_host); - host_and_port = Z_STRVAL_PP(z_host); - if (z_user) { - convert_to_string_ex(z_user); - user = Z_STRVAL_PP(z_user); - if (z_passwd) { - convert_to_string_ex(z_passwd); - passwd = Z_STRVAL_PP(z_passwd); - } - } - } - hashed_details_length = spprintf(&hashed_details, 0, "mysql_%s_%s_%s_%d", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd), client_flags); }