Skip to content

Commit 51b70e4

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fixed bug GH-10270 Unable to return CURL_READFUNC_PAUSE in readfunc callback Fix GH-10672 (pg_lo_open segfaults in the strict_types mode)
2 parents f079aa2 + 512abc2 commit 51b70e4

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

ext/curl/interface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
811811
if (Z_TYPE(retval) == IS_STRING) {
812812
length = MIN((int) (size * nmemb), Z_STRLEN(retval));
813813
memcpy(data, Z_STRVAL(retval), length);
814+
} else if (Z_TYPE(retval) == IS_LONG) {
815+
length = Z_LVAL_P(&retval);
814816
}
815817
zval_ptr_dtor(&retval);
816818
}

ext/curl/tests/curl_pause_001.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test CURL_READFUNC_PAUSE and curl_pause()
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
10+
class Input {
11+
private static $RESPONSES = [
12+
'Foo bar ',
13+
CURL_READFUNC_PAUSE,
14+
'baz qux',
15+
null
16+
];
17+
private int $res = 0;
18+
public function __invoke($ch, $hReadHandle, $iMaxOut)
19+
{
20+
return self::$RESPONSES[$this->res++];
21+
}
22+
}
23+
24+
$inputHandle = fopen(__FILE__, 'r');
25+
26+
$ch = curl_init();
27+
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=input");
28+
curl_setopt($ch, CURLOPT_UPLOAD, 1);
29+
curl_setopt($ch, CURLOPT_READFUNCTION, new Input);
30+
curl_setopt($ch, CURLOPT_INFILE, $inputHandle);
31+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
32+
33+
$mh = curl_multi_init();
34+
curl_multi_add_handle($mh, $ch);
35+
do {
36+
$status = curl_multi_exec($mh, $active);
37+
curl_pause($ch, CURLPAUSE_CONT);
38+
if ($active) {
39+
usleep(100);
40+
curl_multi_select($mh);
41+
}
42+
} while ($active && $status == CURLM_OK);
43+
44+
echo curl_multi_getcontent($ch);
45+
?>
46+
--EXPECT--
47+
string(15) "Foo bar baz qux"

ext/curl/tests/responder/get.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
case 'post':
55
var_dump($_POST);
66
break;
7+
case 'input':
8+
var_dump(file_get_contents('php://input'));
9+
break;
710
case 'getpost':
811
var_dump($_GET);
912
var_dump($_POST);

ext/pgsql/pgsql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ PHP_FUNCTION(pg_lo_open)
23382338
CHECK_PGSQL_LINK(link);
23392339
}
23402340
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(),
2341-
"Ols", &pgsql_link, pgsql_link_ce, &oid_long, &mode) == SUCCESS) {
2341+
"OlS", &pgsql_link, pgsql_link_ce, &oid_long, &mode) == SUCCESS) {
23422342
if (oid_long <= (zend_long)InvalidOid) {
23432343
zend_value_error("Invalid OID value passed");
23442344
RETURN_THROWS();

ext/pgsql/tests/gh10672.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-10672 (pg_lo_open segfaults in the strict_types mode)
3+
--EXTENSIONS--
4+
pgsql
5+
--SKIPIF--
6+
<?php
7+
include("skipif.inc");
8+
?>
9+
--FILE--
10+
<?php
11+
declare(strict_types=1);
12+
13+
include "config.inc";
14+
15+
$db = pg_connect($conn_str);
16+
pg_query($db, "DROP TABLE IF EXISTS gh10672");
17+
pg_query($db, "CREATE TABLE gh10672 (bar text);");
18+
19+
// Begin a transaction
20+
pg_query($db, 'BEGIN');
21+
22+
// Create an empty large object
23+
$oid = pg_lo_create($db);
24+
25+
if ($oid === false) {
26+
die(pg_last_error($db));
27+
}
28+
29+
// Open the large object for writing
30+
$lob = pg_lo_open($db, $oid, 'w');
31+
32+
if ($oid === false) {
33+
die(pg_last_error($db));
34+
}
35+
36+
echo 'The large object has been opened successfully.', PHP_EOL;
37+
?>
38+
--EXPECT--
39+
The large object has been opened successfully.

0 commit comments

Comments
 (0)