Skip to content

Commit eef932a

Browse files
committed
std/dba: validate file permission argument in dba_open()
1 parent a22c56c commit eef932a

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

ext/dba/dba.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
563563
zend_argument_must_not_be_empty_error(3);
564564
RETURN_THROWS();
565565
}
566-
// TODO Check Value for permission
566+
if (permission < 0 || (permission & ~07777) != 0) {
567+
zend_argument_value_error(4, "Invalid file permission value (must be between 0 and 07777)");
568+
RETURN_THROWS();
569+
}
567570
if (map_size < 0) {
568571
zend_argument_value_error(5, "must be greater than or equal to 0");
569572
RETURN_THROWS();

ext/dba/tests/dba_permission.phpt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
DBA permission validation (invalid bits check)
3+
--EXTENSIONS--
4+
dba
5+
--SKIPIF--
6+
<?php
7+
if (!in_array('flatfile', dba_handlers())) die('skip flatfile handler not available');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'test.db';
13+
14+
function test($permission, $filename) {
15+
try {
16+
dba_open($filename, "c", "flatfile", $permission);
17+
echo "OK\n";
18+
} catch (ValueError $e) {
19+
echo "VALUE_ERROR\n";
20+
} catch (Throwable $e) {
21+
echo "ERROR\n";
22+
}
23+
24+
@unlink($filename);
25+
}
26+
27+
/* valid permissions */
28+
test(0777, $filename);
29+
test(0755, $filename);
30+
test(0644, $filename);
31+
test(0000, $filename);
32+
33+
/* invalid permissions */
34+
test(010000, $filename);
35+
test(020000, $filename);
36+
test(-1, $filename);
37+
38+
?>
39+
--EXPECT--
40+
OK
41+
OK
42+
OK
43+
OK
44+
VALUE_ERROR
45+
VALUE_ERROR
46+
VALUE_ERROR
47+
--CLEAN--
48+
<?php
49+
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'test.db';
50+
@unlink($filename);
51+
?>

0 commit comments

Comments
 (0)