Skip to content

Commit e864cb6

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
2 parents bfe63f5 + d1be936 commit e864cb6

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet)
776776
MYSQLND_VIO * vio = conn->vio;
777777
MYSQLND_STATS * stats = conn->stats;
778778
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
779-
zend_uchar * const buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
779+
size_t total_packet_size = packet->auth_data_len + MYSQLND_HEADER_SIZE;
780+
zend_uchar * const buffer = pfc->cmd_buffer.length >= total_packet_size? pfc->cmd_buffer.buffer : mnd_emalloc(total_packet_size);
780781
zend_uchar * p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */
781782

782783
DBG_ENTER("php_mysqlnd_change_auth_response_write");

ext/pgsql/pgsql.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ PHP_FUNCTION(pg_query_params)
11221122
} else {
11231123
zend_string *param_str = zval_try_get_string(tmp);
11241124
if (!param_str) {
1125-
_php_pgsql_free_params(params, num_params);
1125+
_php_pgsql_free_params(params, i);
11261126
RETURN_THROWS();
11271127
}
11281128
params[i] = estrndup(ZSTR_VAL(param_str), ZSTR_LEN(param_str));
@@ -3920,8 +3920,8 @@ PHP_FUNCTION(pg_send_execute)
39203920
params[i] = NULL;
39213921
} else {
39223922
zend_string *tmp_str = zval_try_get_string(tmp);
3923-
if (UNEXPECTED(!tmp)) {
3924-
_php_pgsql_free_params(params, num_params);
3923+
if (UNEXPECTED(!tmp_str)) {
3924+
_php_pgsql_free_params(params, i);
39253925
return;
39263926
}
39273927
params[i] = estrndup(ZSTR_VAL(tmp_str), ZSTR_LEN(tmp_str));

ext/pgsql/tests/bug81720.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #81720 (Uninitialized array in pg_query_params() leading to RCE)
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
include('config.inc');
8+
9+
$conn = pg_connect($conn_str);
10+
11+
try {
12+
pg_query_params($conn, 'SELECT $1, $2', [1, new stdClass()]);
13+
} catch (Throwable $ex) {
14+
echo $ex->getMessage(), PHP_EOL;
15+
}
16+
17+
try {
18+
pg_send_prepare($conn, "my_query", 'SELECT $1, $2');
19+
pg_get_result($conn);
20+
pg_send_execute($conn, "my_query", [1, new stdClass()]);
21+
} catch (Throwable $ex) {
22+
echo $ex->getMessage(), PHP_EOL;
23+
}
24+
?>
25+
--EXPECT--
26+
Object of class stdClass could not be converted to string
27+
Object of class stdClass could not be converted to string

0 commit comments

Comments
 (0)