Skip to content

Commit e6413a9

Browse files
committed
feedback
1 parent 4de7dd2 commit e6413a9

4 files changed

Lines changed: 29 additions & 25 deletions

File tree

ext/pdo/pdo_stmt.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,9 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
271271
}
272272

273273
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_STR && param->max_value_len <= 0 && !Z_ISNULL_P(parameter)) {
274-
zend_bool is_false = (Z_TYPE_P(parameter) == IS_FALSE);
275274
if (!try_convert_to_string(parameter)) {
276275
return false;
277276
}
278-
/* the pgsql's driver does not handle empty string for false bound parameters */
279-
if (is_false) {
280-
ZVAL_STR(parameter, ZSTR_CHAR('0'));
281-
}
282277
} else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_INT && (Z_TYPE_P(parameter) == IS_FALSE || Z_TYPE_P(parameter) == IS_TRUE)) {
283278
convert_to_long(parameter);
284279
} else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL && Z_TYPE_P(parameter) == IS_LONG) {

ext/pgsql/pgsql.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ static void _php_pgsql_free_params(char **params, uint32_t num_params)
12431243
efree(params);
12441244
}
12451245

1246-
static char **php_pgsql_make_arguments(const HashTable *param_arr, int *num_params)
1246+
static char **php_pgsql_make_arguments(const HashTable *param_arr, int *num_params, uint32_t arg_num)
12471247
{
12481248
/* This conversion is safe because of the limit of number of elements in a table. */
12491249
*num_params = (int) zend_hash_num_elements(param_arr);
@@ -1254,6 +1254,10 @@ static char **php_pgsql_make_arguments(const HashTable *param_arr, int *num_para
12541254
ZVAL_DEREF(tmp);
12551255
if (Z_TYPE_P(tmp) == IS_NULL) {
12561256
params[i] = NULL;
1257+
} else if (Z_TYPE_P(tmp) == IS_TRUE || Z_TYPE_P(tmp) == IS_FALSE) {
1258+
zend_argument_value_error(arg_num, "must not contain boolean values, use a string representation instead");
1259+
_php_pgsql_free_params(params, i);
1260+
return NULL;
12571261
} else {
12581262
zend_string *param_str = zval_try_get_string(tmp);
12591263
if (!param_str) {
@@ -1320,7 +1324,7 @@ PHP_FUNCTION(pg_query_params)
13201324
php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first");
13211325
}
13221326

1323-
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params);
1327+
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params, ZEND_NUM_ARGS());
13241328
if (UNEXPECTED(!params)) {
13251329
RETURN_THROWS();
13261330
}
@@ -1503,7 +1507,7 @@ PHP_FUNCTION(pg_execute)
15031507
php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first");
15041508
}
15051509

1506-
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params);
1510+
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params, ZEND_NUM_ARGS());
15071511
if (UNEXPECTED(!params)) {
15081512
RETURN_THROWS();
15091513
}
@@ -4060,7 +4064,7 @@ PHP_FUNCTION(pg_send_query_params)
40604064
"There are results on this connection. Call pg_get_result() until it returns FALSE");
40614065
}
40624066

4063-
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params);
4067+
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params, 3);
40644068
if (UNEXPECTED(!params)) {
40654069
RETURN_THROWS();
40664070
}
@@ -4215,7 +4219,7 @@ PHP_FUNCTION(pg_send_execute)
42154219
"There are results on this connection. Call pg_get_result() until it returns FALSE");
42164220
}
42174221

4218-
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params);
4222+
params = php_pgsql_make_arguments(Z_ARRVAL_P(pv_param_arr), &num_params, 3);
42194223
if (UNEXPECTED(!params)) {
42204224
RETURN_THROWS();
42214225
}

ext/pgsql/tests/33query_params_bool.phpt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
--TEST--
2-
PostgreSQL prepared queries with bool constants
2+
PostgreSQL pg_query_params bool parameter rejection
3+
--EXTENSIONS--
4+
pgsql
35
--SKIPIF--
4-
<?php
5-
include("skipif.inc");
6-
if (!function_exists('pg_prepare')) die('skip function pg_prepare() does not exist');
7-
?>
6+
<?php include("inc/skipif.inc"); ?>
87
--FILE--
98
<?php
109

11-
include('config.inc');
10+
include('inc/config.inc');
1211

1312
$db = pg_connect($conn_str);
1413

15-
$version = pg_version($db);
16-
if ($version['protocol'] >= 3) {
17-
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num >= $1;", array(true));
18-
// bug occurs with false as it turns out as empty.
19-
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num <> $1;", array(false));
20-
pg_free_result($result);
14+
try {
15+
pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num >= $1;", array(true));
16+
} catch (ValueError $e) {
17+
echo $e->getMessage() . "\n";
18+
}
19+
20+
try {
21+
pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num <> $1;", array(false));
22+
} catch (ValueError $e) {
23+
echo $e->getMessage() . "\n";
2124
}
25+
2226
pg_close($db);
2327

2428
echo "OK";
2529
?>
2630
--EXPECT--
31+
pg_query_params(): Argument #3 ($params) must not contain boolean values, use a string representation instead
32+
pg_query_params(): Argument #3 ($params) must not contain boolean values, use a string representation instead
2733
OK
28-

ext/zip/php_zip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,14 @@ int php_zip_glob(zend_string *spattern, zend_long flags, zval *return_value) /*
676676

677677
/* now catch the FreeBSD style of "no matches" */
678678
if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
679-
globfree(&globbuf);
679+
php_globfree(&globbuf);
680680
return 0;
681681
}
682682

683683
/* we assume that any glob pattern will match files from one directory only
684684
so checking the dirname of the first match should be sufficient */
685685
if (ZIP_OPENBASEDIR_CHECKPATH(globbuf.gl_pathv[0])) {
686-
globfree(&globbuf);
686+
php_globfree(&globbuf);
687687
return -1;
688688
}
689689

0 commit comments

Comments
 (0)