Skip to content

Commit 5975f33

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
2 parents b8ac207 + 5f90134 commit 5975f33

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ext/pdo_sqlite/sqlite_driver.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ static zend_string *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const zend_string
226226
/* NB: doesn't handle binary strings... use prepared stmts for that */
227227
static zend_string* sqlite_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype)
228228
{
229-
char *quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3);
229+
char *quoted;
230+
if (unquotedlen > (INT_MAX - 3) / 2) {
231+
return 0;
232+
}
233+
quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3);
230234
/* TODO use %Q format? */
231235
sqlite3_snprintf(2*ZSTR_LEN(unquoted) + 3, quoted, "'%q'", ZSTR_VAL(unquoted));
232236
zend_string *quoted_str = zend_string_init(quoted, strlen(quoted), 0);

ext/pdo_sqlite/tests/bug81740.phpt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #81740 (PDO::quote() may return unquoted string)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
6+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
7+
?>
8+
--INI--
9+
memory_limit=-1
10+
--FILE--
11+
<?php
12+
$pdo = new PDO("sqlite::memory:");
13+
$string = str_repeat("a", 0x80000000);
14+
var_dump($pdo->quote($string));
15+
?>
16+
--EXPECT--
17+
bool(false)

0 commit comments

Comments
 (0)