Skip to content

Commit eb3e7a2

Browse files
sim1984SakiTakamachi
authored andcommitted
ext/pdo_firebird: Fixed GH-15604 Always make input parameters nullable (#15605)
Fixes #15604 Closes #15605
1 parent b221f21 commit eb3e7a2

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ PHP NEWS
1414
- GD:
1515
. Added gdImageClone to bundled libgd. (David Carlier)
1616

17+
- PDO_Firebird:
18+
. Fixed GH-15604 (Always make input parameters nullable). (sim1984)
19+
1720
27 Aug 2024, PHP 8.4.0beta4
1821

1922
- Core:

ext/pdo_firebird/firebird_driver.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,14 @@ static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
681681
if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
682682
break;
683683
}
684+
685+
/* make all parameters nullable */
686+
unsigned int i;
687+
XSQLVAR* var;
688+
for (i = 0, var = S->in_sqlda->sqlvar; i < S->in_sqlda->sqld; i++, var++) {
689+
/* The low bit of sqltype indicates that the parameter can take a NULL value */
690+
var->sqltype |= 1;
691+
}
684692
}
685693

686694
stmt->driver_data = S;

ext/pdo_firebird/tests/bug_15604.phpt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
--TEST--
2+
Bug #15604 It is not possible to pass a NULL value as an input parameter if the field is marked as NOT NULL.
3+
--EXTENSIONS--
4+
pdo_firebird
5+
--SKIPIF--
6+
<?php require('skipif.inc'); ?>
7+
--XLEAK--
8+
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
9+
See https://github.com/FirebirdSQL/firebird/issues/7849
10+
--FILE--
11+
<?php
12+
require_once 'testdb.inc';
13+
14+
$dbh = getDbConnection();
15+
16+
$dbh->exec('
17+
recreate table t_bug_15604 (
18+
id bigint not null,
19+
a int not null,
20+
b int,
21+
constraint pk_bug_15604 primary key(id)
22+
)
23+
');
24+
25+
$dbh->exec('recreate sequence g_bug_15604');
26+
27+
$dbh->exec(<<<'SQL'
28+
create or alter trigger t_bug_15604_bi0 for t_bug_15604
29+
active before insert position 0
30+
as
31+
begin
32+
if (new.id is null) then
33+
new.id = next value for g_bug_15604;
34+
end
35+
SQL
36+
);
37+
38+
$stmt = $dbh->prepare('insert into t_bug_15604(id, a, b) values(?, ?, ?)');
39+
$stmt->execute([null, 1, 2]);
40+
$stmt->execute([2, 2, null]);
41+
unset($stmt);
42+
43+
$stmt2 = $dbh->prepare('SELECT id, a, b FROM t_bug_15604 WHERE id = ?');
44+
45+
$stmt2->execute([null]);
46+
$data = $stmt2->fetch(\PDO::FETCH_ASSOC);
47+
$stmt2->closeCursor();
48+
var_dump($data);
49+
50+
$stmt2->execute([2]);
51+
$data = $stmt2->fetch(\PDO::FETCH_ASSOC);
52+
$stmt2->closeCursor();
53+
var_dump($data);
54+
55+
unset($stmt2);
56+
57+
echo "\nOK\n";
58+
?>
59+
--CLEAN--
60+
<?php
61+
require_once 'testdb.inc';
62+
$dbh = getDbConnection();
63+
@$dbh->exec('drop table t_bug_15604');
64+
@$dbh->exec('drop sequence g_bug_15604');
65+
unset($dbh);
66+
?>
67+
--EXPECT--
68+
bool(false)
69+
array(3) {
70+
["ID"]=>
71+
int(2)
72+
["A"]=>
73+
int(2)
74+
["B"]=>
75+
NULL
76+
}
77+
78+
OK

0 commit comments

Comments
 (0)