Skip to content

Commit bcbf8aa

Browse files
cmb69smalyshev
authored andcommitted
Fix #76450: SIGSEGV in firebird_stmt_execute
We need to verify that the `result_size` is not larger than our buffer, and also should make sure that the `len` which is passed to `isc_vax_integer()` has a permissible value; otherwise we bail out.
1 parent 286162e commit bcbf8aa

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

ext/pdo_firebird/firebird_statement.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,14 @@ static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
133133
}
134134
if (result[0] == isc_info_sql_records) {
135135
unsigned i = 3, result_size = isc_vax_integer(&result[1], 2);
136+
if (result_size > sizeof(result)) {
137+
goto error;
138+
}
136139
while (result[i] != isc_info_end && i < result_size) {
137140
short len = (short) isc_vax_integer(&result[i + 1], 2);
141+
if (len != 1 && len != 2 && len != 4) {
142+
goto error;
143+
}
138144
if (result[i] != isc_info_req_select_count) {
139145
affected_rows += isc_vax_integer(&result[i + 3], len);
140146
}
@@ -158,6 +164,7 @@ static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
158164
return 1;
159165
} while (0);
160166

167+
error:
161168
RECORD_ERROR(stmt);
162169

163170
return 0;

ext/pdo_firebird/tests/bug_76450.data

464 Bytes
Binary file not shown.

ext/pdo_firebird/tests/bug_76450.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #76450 (SIGSEGV in firebird_stmt_execute)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_firebird')) die("skip pdo_firebird extension not available");
6+
if (!extension_loaded('sockets')) die("skip sockets extension not available");
7+
?>
8+
--FILE--
9+
<?php
10+
require_once "payload_server.inc";
11+
12+
$address = run_server(__DIR__ . "/bug_76450.data");
13+
14+
// no need to change the credentials; we're running against a fake server
15+
$dsn = "firebird:dbname=inet://$address/test";
16+
$username = 'SYSDBA';
17+
$password = 'masterkey';
18+
19+
$dbh = new PDO($dsn, $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
20+
$sql = "EXECUTE PROCEDURE test_proc 123";
21+
$query = $dbh->prepare($sql);
22+
try {
23+
$query->execute();
24+
} catch (Exception $ex) {
25+
echo "{$ex->getMessage()}\n";
26+
}
27+
?>
28+
--EXPECT--
29+
SQLSTATE[HY000]: General error

0 commit comments

Comments
 (0)