Skip to content

Commit 07643df

Browse files
committed
Fix GH-19885: dba_fetch() overflow on skip argument.
1 parent 6eb3fae commit 07643df

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

ext/dba/dba.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,11 @@ PHP_FUNCTION(dba_fetch)
984984
ZEND_PARSE_PARAMETERS_END();
985985
}
986986

987+
if (ZEND_LONG_EXCEEDS_INT(skip)) {
988+
zend_argument_value_error(3, "must be between %d and %d", INT_MIN, INT_MAX);
989+
RETURN_THROWS();
990+
}
991+
987992
DBA_FETCH_RESOURCE(info, id);
988993

989994
if (key_ht) {

ext/dba/tests/gh19885.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
GH-19885 (dba_fetch() segfault on large skip values)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6+
require_once(__DIR__ .'/skipif.inc');
7+
die("info $HND handler used");
8+
?>
9+
--FILE--
10+
<?php
11+
$handler = 'cdb';
12+
$db_file = __DIR__.'/test.cdb';
13+
$db =dba_open($db_file, "r", $handler);
14+
try {
15+
dba_fetch("1", $db, PHP_INT_MIN);
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage(), PHP_EOL;
18+
}
19+
20+
try {
21+
dba_fetch("1", $db, PHP_INT_MAX);
22+
} catch (\ValueError $e) {
23+
echo $e->getMessage(), PHP_EOL;
24+
}
25+
// negative skip needs to remain acceptable albeit corrected down the line
26+
var_dump(dba_fetch("1", $db, -1000000));
27+
?>
28+
--EXPECTF--
29+
dba_fetch(): Argument #3 ($skip) must be between %i and %d
30+
dba_fetch(): Argument #3 ($skip) must be between %i and %d
31+
32+
Notice: dba_fetch(): Handler cdb accepts only skip values greater than or equal to zero, using skip=0 in %s on line %d
33+
string(1) "1"

0 commit comments

Comments
 (0)