Skip to content

Commit ec5b872

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 7f44559 + 32b6eac commit ec5b872

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

ext/pdo/pdo_dbh.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ PHP_METHOD(PDO, query)
11641164
PHP_METHOD(PDO, quote)
11651165
{
11661166
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
1167-
zend_string *str;
1167+
zend_string *str, *quoted;
11681168
zend_long paramtype = PDO_PARAM_STR;
11691169

11701170
ZEND_PARSE_PARAMETERS_START(1, 2)
@@ -1180,8 +1180,14 @@ PHP_METHOD(PDO, quote)
11801180
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support quoting");
11811181
RETURN_FALSE;
11821182
}
1183+
quoted = dbh->methods->quoter(dbh, str, paramtype);
11831184

1184-
RETURN_STR(dbh->methods->quoter(dbh, str, paramtype));
1185+
if (quoted == NULL) {
1186+
PDO_HANDLE_DBH_ERR();
1187+
RETURN_FALSE;
1188+
}
1189+
1190+
RETURN_STR(quoted);
11851191
}
11861192
/* }}} */
11871193

ext/pdo/pdo_sql_parser.re

+7
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ safe:
242242
if (buf) {
243243
zend_string_release_ex(buf, 0);
244244
}
245+
if (plc->quoted == NULL) {
246+
/* bork */
247+
ret = -1;
248+
strncpy(stmt->error_code, stmt->dbh->error_code, 6);
249+
goto clean_up;
250+
}
251+
245252
} else {
246253
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource");
247254
ret = -1;

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 (ZSTR_LEN(unquoted) > (INT_MAX - 3) / 2) {
231+
return NULL;
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)