Skip to content

Commit e8ecd20

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: ext/pdo: Validate Oracle null handling modes
2 parents 4526719 + c122224 commit e8ecd20

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎ext/pdo/pdo_dbh.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,16 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value, u
852852
if (!pdo_get_long_param(&lval, value)) {
853853
return false;
854854
}
855-
/* TODO Check for valid value (NULL_NATURAL, NULL_EMPTY_STRING, NULL_TO_STRING)? */
856-
dbh->oracle_nulls = lval;
857-
return true;
855+
switch (lval) {
856+
case PDO_NULL_NATURAL:
857+
case PDO_NULL_EMPTY_STRING:
858+
case PDO_NULL_TO_STRING:
859+
dbh->oracle_nulls = lval;
860+
return true;
861+
default:
862+
zend_argument_value_error(value_arg_num, "PDO::ATTR_ORACLE_NULLS must be one of the PDO::NULL_* constants");
863+
return false;
864+
}
858865

859866
case PDO_ATTR_DEFAULT_FETCH_MODE:
860867
if (Z_TYPE_P(value) == IS_ARRAY) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
PDO Common: Invalid Oracle null handling modes do not change the attribute
3+
--EXTENSIONS--
4+
pdo
5+
--SKIPIF--
6+
<?php
7+
$dir = getenv('REDIR_TEST_DIR');
8+
if ($dir === false) {
9+
die('skip no driver');
10+
}
11+
require_once $dir . 'pdo_test.inc';
12+
PDOTest::skip();
13+
?>
14+
--FILE--
15+
<?php
16+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
17+
$pdo = PDOTest::factory();
18+
19+
foreach ([PDO::NULL_NATURAL, PDO::NULL_EMPTY_STRING, PDO::NULL_TO_STRING] as $value) {
20+
echo "Valid mode: ";
21+
var_dump($pdo->setAttribute(PDO::ATTR_ORACLE_NULLS, $value));
22+
var_dump($pdo->getAttribute(PDO::ATTR_ORACLE_NULLS));
23+
}
24+
25+
foreach ([-1, 3, 4, PHP_INT_MAX] as $value) {
26+
try {
27+
$pdo->setAttribute(PDO::ATTR_ORACLE_NULLS, $value);
28+
} catch (ValueError $e) {
29+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
30+
}
31+
echo "Unchanged mode: ";
32+
var_dump($pdo->getAttribute(PDO::ATTR_ORACLE_NULLS));
33+
}
34+
?>
35+
--EXPECT--
36+
Valid mode: bool(true)
37+
int(0)
38+
Valid mode: bool(true)
39+
int(1)
40+
Valid mode: bool(true)
41+
int(2)
42+
ValueError: PDO::setAttribute(): Argument #2 ($value) PDO::ATTR_ORACLE_NULLS must be one of the PDO::NULL_* constants
43+
Unchanged mode: int(2)
44+
ValueError: PDO::setAttribute(): Argument #2 ($value) PDO::ATTR_ORACLE_NULLS must be one of the PDO::NULL_* constants
45+
Unchanged mode: int(2)
46+
ValueError: PDO::setAttribute(): Argument #2 ($value) PDO::ATTR_ORACLE_NULLS must be one of the PDO::NULL_* constants
47+
Unchanged mode: int(2)
48+
ValueError: PDO::setAttribute(): Argument #2 ($value) PDO::ATTR_ORACLE_NULLS must be one of the PDO::NULL_* constants
49+
Unchanged mode: int(2)

0 commit comments

Comments
 (0)