Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ PHP NEWS
- PDO_ODBC:
. Fixed bug GH-20726 (Crash with ODBC connection pooling when the DSN
carries no credentials). (iliaal)
. Fixed bug GH-22665 (Out-of-bounds write when the ODBC driver reports a
diagnostic message length beyond the error buffer). (iliaal)

- Phar:
. Fixed inconsistent handling of the magic ".phar" directory. Paths such as
Expand Down
2 changes: 2 additions & 0 deletions ext/pdo_odbc/odbc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement,

if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
errmsgsize = 0;
} else if ((size_t) errmsgsize >= sizeof(einfo->last_err_msg)) {
errmsgsize = sizeof(einfo->last_err_msg) - 1;
}

einfo->last_err_msg[errmsgsize] = '\0';
Expand Down
30 changes: 30 additions & 0 deletions ext/pdo_odbc/tests/gh22665.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
GH-22665 (OOB write in pdo_odbc_error when the driver reports a long message)
--EXTENSIONS--
pdo_odbc
--SKIPIF--
<?php
try {
$pdo = new PDO("odbc:Driver=SQLite3;Database=:memory:");
} catch (PDOException $e) {
die("skip requires the SQLite3 ODBC driver");
}
?>
--FILE--
<?php
$pdo = new PDO("odbc:Driver=SQLite3;Database=:memory:", null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT,
]);

// A failing query with a long identifier makes the driver report a diagnostic
// message length >= the fixed last_err_msg buffer. The terminator write must
// stay inside the buffer.
$pdo->query('SELECT * FROM "' . str_repeat('A', 4096) . '"');
$info = $pdo->errorInfo();

echo "sqlstate: ", $info[0], "\n";
echo "done\n";
?>
--EXPECT--
sqlstate: HY000
done
Loading