Skip to content

Commit 08089f0

Browse files
committed
Fixed #69356: PDOStatement::debugDumpParams() truncates query
1 parent 751d19f commit 08089f0

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PHP NEWS
88
. Fixed bug #74761 (Unary operator expected error on some systems). (petk)
99
. Fixed bug #73900 (Use After Free in unserialize() SplFixedArray). (nikic)
1010

11+
- PDO:
12+
. Fixed bug #69356 (PDOStatement::debugDumpParams() truncates query). (Adam
13+
Baratz)
14+
1115
- SPL:
1216
. Fixed bug #73471 (PHP freezes with AppendIterator). (jhdxr)
1317

ext/pdo/pdo_stmt.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,9 +2110,10 @@ static PHP_METHOD(PDOStatement, debugDumpParams)
21102110
RETURN_FALSE;
21112111
}
21122112

2113-
php_stream_printf(out, "SQL: [%zd] %.*s\n",
2114-
stmt->query_stringlen,
2115-
(int) stmt->query_stringlen, stmt->query_string);
2113+
/* break into multiple operations so query string won't be truncated at FORMAT_CONV_MAX_PRECISION */
2114+
php_stream_printf(out, "SQL: [%zd] ", stmt->query_stringlen);
2115+
php_stream_write(out, stmt->query_string, stmt->query_stringlen);
2116+
php_stream_write(out, "\n", 1);
21162117

21172118
php_stream_printf(out, "Params: %d\n",
21182119
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0);

ext/pdo/tests/bug_69356.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
PDO Common: Bug #69356 (PDOStatement::debugDumpParams() truncates query)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo')) die('skip');
6+
$dir = getenv('REDIR_TEST_DIR');
7+
if (false == $dir) die('skip no driver');
8+
require_once $dir . 'pdo_test.inc';
9+
PDOTest::skip();
10+
?>
11+
--FILE--
12+
<?php
13+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
14+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15+
16+
$db = PDOTest::factory();
17+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
18+
$stmt = $db->query("
19+
SELECT '
20+
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
21+
This is a debug function, which dump directly the data on the normal output.
22+
Tip:
23+
As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
24+
This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed.
25+
'
26+
");
27+
var_dump($stmt->debugDumpParams());
28+
?>
29+
--EXPECT--
30+
SQL: [835]
31+
SELECT '
32+
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
33+
This is a debug function, which dump directly the data on the normal output.
34+
Tip:
35+
As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
36+
This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed.
37+
'
38+
39+
Params: 0
40+
NULL

0 commit comments

Comments
 (0)