From: Ilia Alshanetsky Date: Wed, 1 Oct 2008 20:31:02 +0000 (+0000) Subject: MFB: Fixed bug #46206 (pg_query_params/pg_execute convert passed values to X-Git-Tag: BEFORE_HEAD_NS_CHANGE~302 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8710c3a916acba71796855eddf5ab5419cbbd974;p=php MFB: Fixed bug #46206 (pg_query_params/pg_execute convert passed values to strings). --- diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index c59e31c686..d8715c9442 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1711,6 +1711,10 @@ PHP_FUNCTION(pg_query) static void _php_pgsql_free_params(char **params, int num_params) { if (num_params > 0) { + int i; + for (i = 0; i < num_params; i++) { + efree(params[i]); + } efree(params); } } @@ -1729,7 +1733,6 @@ PHP_FUNCTION(pg_query_params) int leftover = 0; int num_params = 0; char **params = NULL; - unsigned char otype; PGconn *pgsql; PGresult *pgsql_result; ExecStatusType status; @@ -1778,19 +1781,20 @@ PHP_FUNCTION(pg_query_params) RETURN_FALSE; } - otype = (*tmp)->type; - convert_to_string_ex(tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; - } - else { - params[i] = Z_STRVAL_PP(tmp); + } else { + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr)); @@ -1936,7 +1940,6 @@ PHP_FUNCTION(pg_execute) int leftover = 0; int num_params = 0; char **params = NULL; - unsigned char otype; PGconn *pgsql; PGresult *pgsql_result; ExecStatusType status; @@ -1985,19 +1988,20 @@ PHP_FUNCTION(pg_execute) RETURN_FALSE; } - otype = (*tmp)->type; - SEPARATE_ZVAL(tmp); - convert_to_string_ex(tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; } else { - params[i] = Z_STRVAL_PP(tmp); + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr)); @@ -4548,7 +4552,6 @@ PHP_FUNCTION(pg_send_query_params) zval *pgsql_link, *pv_param_arr, **tmp; int num_params = 0; char **params = NULL; - unsigned char otype; char *query; int query_len, id = -1; PGconn *pgsql; @@ -4590,20 +4593,20 @@ PHP_FUNCTION(pg_send_query_params) RETURN_FALSE; } - otype = (*tmp)->type; - SEPARATE_ZVAL(tmp); - convert_to_string_ex(tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; - } - else { - params[i] = Z_STRVAL_PP(tmp); + } else { + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr)); @@ -4686,7 +4689,6 @@ PHP_FUNCTION(pg_send_execute) zval *pv_param_arr, **tmp; int num_params = 0; char **params = NULL; - unsigned char otype; char *stmtname; int stmtname_len, id = -1; PGconn *pgsql; @@ -4728,19 +4730,20 @@ PHP_FUNCTION(pg_send_execute) RETURN_FALSE; } - otype = (*tmp)->type; - convert_to_string(*tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; - } - else { - params[i] = Z_STRVAL_PP(tmp); + } else { + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));