Skip to content

Commit 6acfb79

Browse files
committed
Fix #67465: NULL Pointer dereference in odbc_handle_preparer
We have to initialize `stmt->driver_data` before we use it. Closes GH-6225.
1 parent 4dfbf07 commit 6acfb79

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP NEWS
2121
. Fixed bug #80083 (Optimizer pass 6 removes variables used for ibm_db2 data
2222
binding). (Nikita)
2323

24+
- PDO_ODBC:
25+
. Fixed bug #67465 (NULL Pointer dereference in odbc_handle_preparer). (cmb)
26+
2427
- Standard:
2528
. Fixed bug #80114 (parse_url does not accept URLs with port 0). (cmb, twosee)
2629
. Fixed bug #76943 (Inconsistent stream_wrapper_restore() errors). (cmb)

ext/pdo_odbc/odbc_driver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
179179
return 0;
180180
}
181181

182+
stmt->driver_data = S;
183+
182184
cursor_type = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY);
183185
if (cursor_type != PDO_CURSOR_FWDONLY) {
184186
rc = SQLSetStmtAttr(S->stmt, SQL_ATTR_CURSOR_SCROLLABLE, (void*)SQL_SCROLLABLE, 0);
@@ -197,7 +199,6 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
197199
efree(nsql);
198200
}
199201

200-
stmt->driver_data = S;
201202
stmt->methods = &odbc_stmt_methods;
202203

203204
if (rc != SQL_SUCCESS) {

ext/pdo_odbc/tests/bug67465.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #67465 (NULL Pointer dereference in odbc_handle_preparer)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_odbc')) die('skip pdo_odbc extension not available');
6+
require 'ext/pdo/tests/pdo_test.inc';
7+
PDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require 'ext/pdo/tests/pdo_test.inc';
12+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
13+
$db->prepare("SELECT 1", [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);
14+
echo "done\n";
15+
?>
16+
--EXPECT--
17+
done

0 commit comments

Comments
 (0)