1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-19885: dba_fetch() overflow on skip argument.

close GH-19887
This commit is contained in:
David Carlier
2025-09-19 12:29:46 +01:00
parent 7a1bb71127
commit 933e087843
3 changed files with 43 additions and 0 deletions

3
NEWS
View File

@@ -19,6 +19,9 @@ PHP NEWS
. Fixed GH-17159: "P" format for ::createFromFormat swallows string literals.
(nielsdos)
- DBA:
. Fixed GH-19885 (dba_fetch() overflow on skip argument). (David Carlier)
- Curl:
. Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead
of the curl_copy_handle() function to clone a CurlHandle. (timwolla)

View File

@@ -984,6 +984,11 @@ PHP_FUNCTION(dba_fetch)
ZEND_PARSE_PARAMETERS_END();
}
if (ZEND_LONG_EXCEEDS_INT(skip)) {
zend_argument_value_error(3, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}
DBA_FETCH_RESOURCE(info, id);
if (key_ht) {

View File

@@ -0,0 +1,35 @@
--TEST--
GH-19885 (dba_fetch() segfault on large skip values)
--EXTENSIONS--
dba
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
$handler = 'cdb';
require_once(__DIR__ .'/skipif.inc');
?>
--FILE--
<?php
$handler = 'cdb';
$db_file = __DIR__.'/test.cdb';
$db =dba_open($db_file, "r", $handler);
try {
dba_fetch("1", $db, PHP_INT_MIN);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
dba_fetch("1", $db, PHP_INT_MAX);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
// negative skip needs to remain acceptable albeit corrected down the line
var_dump(dba_fetch("1", $db, -1000000));
?>
--EXPECTF--
dba_fetch(): Argument #3 ($skip) must be between -%d and %d
dba_fetch(): Argument #3 ($skip) must be between -%d and %d
Notice: dba_fetch(): Handler cdb accepts only skip values greater than or equal to zero, using skip=0 in %s on line %d
string(1) "1"