diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2007-12-20 00:31:49 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2007-12-20 00:31:49 +0000 |
commit | c21ef044a7823760fd7f952594d5f66a3355f7e0 (patch) | |
tree | 497551f442d02e637b93c3f15425a65d41cb3b6f /ext/mysql/php_mysql.c | |
parent | a81fccc47d5a3b681281cf28b00b7744cf83dd76 (diff) | |
download | php-git-c21ef044a7823760fd7f952594d5f66a3355f7e0.tar.gz |
MFB: Fixed bug #43635 (mysql extension ingores INI settings on NULL values
passed to mysql_connect())
Diffstat (limited to 'ext/mysql/php_mysql.c')
-rw-r--r-- | ext/mysql/php_mysql.c | 109 |
1 files changed, 21 insertions, 88 deletions
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); } |