Skip to content

Fix GH-17746: Signed integer overflow when setting ATTR_TIMEOUT #17854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions ext/pdo_sqlite/sqlite_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ static bool pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
if (!pdo_get_long_param(&lval, val)) {
return false;
}
if (lval > INT_MAX / 1000) {
return false;
}
lval = MAX(lval, 0);
sqlite3_busy_timeout(H->db, lval * 1000);
return true;
case PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES:
Expand Down
15 changes: 15 additions & 0 deletions ext/pdo_sqlite/tests/gh17746.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-17746 (Signed integer overflow when setting ATTR_TIMEOUT)
--EXTENSIONS--
pdo_sqlite
--CREDITS--
YuanchengJiang
--FILE--
<?php
$pdo = new PDO("sqlite::memory:");
var_dump($pdo->setAttribute(PDO::ATTR_TIMEOUT, -1));
var_dump($pdo->setAttribute(PDO::ATTR_TIMEOUT, intdiv(0x7fffffff, 1000) + 1));
?>
--EXPECT--
bool(true)
bool(false)
Loading