Skip to content

Commit 9ba2667

Browse files
committed
Merge branch 'PHP-8.4'
2 parents fe87ba4 + 2309cac commit 9ba2667

File tree

2 files changed

+97
-8
lines changed

2 files changed

+97
-8
lines changed

ext/pgsql/pgsql.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,14 +1136,17 @@ PHP_FUNCTION(pg_query)
11361136

11371137
link = FETCH_DEFAULT_LINK();
11381138
CHECK_DEFAULT_LINK(link);
1139-
} else {
1139+
} else if (ZEND_NUM_ARGS() == 2) {
11401140
ZEND_PARSE_PARAMETERS_START(2, 2)
11411141
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
11421142
Z_PARAM_STRING(query, query_len)
11431143
ZEND_PARSE_PARAMETERS_END();
11441144

11451145
link = Z_PGSQL_LINK_P(pgsql_link);
11461146
CHECK_PGSQL_LINK(link);
1147+
} else {
1148+
zend_wrong_parameters_count_error(1, 2);
1149+
RETURN_THROWS();
11471150
}
11481151

11491152
pgsql = link->conn;
@@ -1234,7 +1237,7 @@ PHP_FUNCTION(pg_query_params)
12341237

12351238
link = FETCH_DEFAULT_LINK();
12361239
CHECK_DEFAULT_LINK(link);
1237-
} else {
1240+
} else if (ZEND_NUM_ARGS() == 3) {
12381241
ZEND_PARSE_PARAMETERS_START(3, 3)
12391242
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
12401243
Z_PARAM_STRING(query, query_len)
@@ -1243,6 +1246,9 @@ PHP_FUNCTION(pg_query_params)
12431246

12441247
link = Z_PGSQL_LINK_P(pgsql_link);
12451248
CHECK_PGSQL_LINK(link);
1249+
} else {
1250+
zend_wrong_parameters_count_error(2, 3);
1251+
RETURN_THROWS();
12461252
}
12471253

12481254
pgsql = link->conn;
@@ -1344,7 +1350,7 @@ PHP_FUNCTION(pg_prepare)
13441350

13451351
link = FETCH_DEFAULT_LINK();
13461352
CHECK_DEFAULT_LINK(link);
1347-
} else {
1353+
} else if (ZEND_NUM_ARGS() == 3) {
13481354
ZEND_PARSE_PARAMETERS_START(3, 3)
13491355
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
13501356
Z_PARAM_STRING(stmtname, stmtname_len)
@@ -1353,6 +1359,9 @@ PHP_FUNCTION(pg_prepare)
13531359

13541360
link = Z_PGSQL_LINK_P(pgsql_link);
13551361
CHECK_PGSQL_LINK(link);
1362+
} else {
1363+
zend_wrong_parameters_count_error(2, 3);
1364+
RETURN_THROWS();
13561365
}
13571366

13581367
pgsql = link->conn;
@@ -1430,7 +1439,7 @@ PHP_FUNCTION(pg_execute)
14301439

14311440
link = FETCH_DEFAULT_LINK();
14321441
CHECK_DEFAULT_LINK(link);
1433-
} else {
1442+
} else if (ZEND_NUM_ARGS() == 3) {
14341443
ZEND_PARSE_PARAMETERS_START(3, 3)
14351444
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
14361445
Z_PARAM_STRING(stmtname, stmtname_len)
@@ -1439,6 +1448,9 @@ PHP_FUNCTION(pg_execute)
14391448

14401449
link = Z_PGSQL_LINK_P(pgsql_link);
14411450
CHECK_PGSQL_LINK(link);
1451+
} else {
1452+
zend_wrong_parameters_count_error(2, 3);
1453+
RETURN_THROWS();
14421454
}
14431455

14441456
pgsql = link->conn;
@@ -2230,7 +2242,7 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
22302242
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
22312243
Z_PARAM_STR_OR_LONG(field_name, field_offset)
22322244
ZEND_PARSE_PARAMETERS_END();
2233-
} else {
2245+
} else if (ZEND_NUM_ARGS() == 3) {
22342246
ZEND_PARSE_PARAMETERS_START(3, 3)
22352247
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
22362248
if (nullable_row) {
@@ -2240,6 +2252,9 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
22402252
}
22412253
Z_PARAM_STR_OR_LONG(field_name, field_offset)
22422254
ZEND_PARSE_PARAMETERS_END();
2255+
} else {
2256+
zend_wrong_parameters_count_error(2, 3);
2257+
RETURN_THROWS();
22432258
}
22442259

22452260
pg_result = Z_PGSQL_RESULT_P(result);
@@ -3070,14 +3085,17 @@ PHP_FUNCTION(pg_set_error_verbosity)
30703085

30713086
link = FETCH_DEFAULT_LINK();
30723087
CHECK_DEFAULT_LINK(link);
3073-
} else {
3088+
} else if (ZEND_NUM_ARGS() == 2) {
30743089
ZEND_PARSE_PARAMETERS_START(2, 2)
30753090
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
30763091
Z_PARAM_LONG(verbosity)
30773092
ZEND_PARSE_PARAMETERS_END();
30783093

30793094
link = Z_PGSQL_LINK_P(pgsql_link);
30803095
CHECK_PGSQL_LINK(link);
3096+
} else {
3097+
zend_wrong_parameters_count_error(1, 2);
3098+
RETURN_THROWS();
30813099
}
30823100

30833101
pgsql = link->conn;
@@ -3148,14 +3166,17 @@ PHP_FUNCTION(pg_set_client_encoding)
31483166

31493167
link = FETCH_DEFAULT_LINK();
31503168
CHECK_DEFAULT_LINK(link);
3151-
} else {
3169+
} else if (ZEND_NUM_ARGS() == 2) {
31523170
ZEND_PARSE_PARAMETERS_START(2, 2)
31533171
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
31543172
Z_PARAM_STRING(encoding, encoding_len)
31553173
ZEND_PARSE_PARAMETERS_END();
31563174

31573175
link = Z_PGSQL_LINK_P(pgsql_link);
31583176
CHECK_PGSQL_LINK(link);
3177+
} else {
3178+
zend_wrong_parameters_count_error(1, 2);
3179+
RETURN_THROWS();
31593180
}
31603181

31613182
pgsql = link->conn;
@@ -3242,14 +3263,17 @@ PHP_FUNCTION(pg_put_line)
32423263

32433264
link = FETCH_DEFAULT_LINK();
32443265
CHECK_DEFAULT_LINK(link);
3245-
} else {
3266+
} else if (ZEND_NUM_ARGS() == 2) {
32463267
ZEND_PARSE_PARAMETERS_START(2, 2)
32473268
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
32483269
Z_PARAM_STRING(query, query_len)
32493270
ZEND_PARSE_PARAMETERS_END();
32503271

32513272
link = Z_PGSQL_LINK_P(pgsql_link);
32523273
CHECK_PGSQL_LINK(link);
3274+
} else {
3275+
zend_wrong_parameters_count_error(1, 2);
3276+
RETURN_THROWS();
32533277
}
32543278

32553279
pgsql = link->conn;

ext/pgsql/tests/gh17165.phpt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
Fix pg_query()/pg_query_params()/pg_prepare()/pg_execute()/pg_set_error_verbosity()/pg_set_client_encoding()/pg_put_line() pg field infos calls ArgumentCountError message.
3+
--EXTENSIONS--
4+
pgsql
5+
--SKIPIF--
6+
<?php
7+
include("skipif.inc");
8+
?>
9+
--FILE--
10+
<?php
11+
12+
13+
include "config.inc";
14+
15+
$db = pg_connect($conn_str);
16+
try {
17+
pg_query("a", "b", "c");
18+
} catch (ArgumentCountError $e) {
19+
echo $e->getMessage(), PHP_EOL;
20+
}
21+
22+
try {
23+
pg_query_params($db, "b", array(), "d");
24+
} catch (ArgumentCountError $e) {
25+
echo $e->getMessage(), PHP_EOL;
26+
}
27+
28+
try {
29+
pg_prepare($db, "a", "b", "c");
30+
} catch (ArgumentCountError $e) {
31+
echo $e->getMessage(), PHP_EOL;
32+
}
33+
34+
try {
35+
pg_set_error_verbosity($db, 0, PHP_INT_MAX);
36+
} catch (ArgumentCountError $e) {
37+
echo $e->getMessage(), PHP_EOL;
38+
}
39+
40+
try {
41+
pg_set_client_encoding($db, "foo", "bar");
42+
} catch (ArgumentCountError $e) {
43+
echo $e->getMessage(), PHP_EOL;
44+
}
45+
46+
try {
47+
pg_put_line($db, "my", "data");
48+
} catch (ArgumentCountError $e) {
49+
echo $e->getMessage(), PHP_EOL;
50+
}
51+
52+
try {
53+
pg_field_is_null($db, false, "myfield", new stdClass());
54+
} catch (ArgumentCountError $e) {
55+
echo $e->getMessage(), PHP_EOL;
56+
}
57+
?>
58+
--EXPECT--
59+
pg_query() expects at most 2 arguments, 3 given
60+
pg_query_params() expects at most 3 arguments, 4 given
61+
pg_prepare() expects at most 3 arguments, 4 given
62+
pg_set_error_verbosity() expects at most 2 arguments, 3 given
63+
pg_set_client_encoding() expects at most 2 arguments, 3 given
64+
pg_put_line() expects at most 2 arguments, 3 given
65+
pg_field_is_null() expects at most 3 arguments, 4 given

0 commit comments

Comments
 (0)