Skip to content

Commit

Permalink
Fixed #69356: PDOStatement::debugDumpParams() truncates query
Browse files Browse the repository at this point in the history
  • Loading branch information
adambaratz committed Jun 29, 2017
1 parent 751d19f commit 08089f0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ PHP NEWS
. Fixed bug #74761 (Unary operator expected error on some systems). (petk)
. Fixed bug #73900 (Use After Free in unserialize() SplFixedArray). (nikic)

- PDO:
. Fixed bug #69356 (PDOStatement::debugDumpParams() truncates query). (Adam
Baratz)

- SPL:
. Fixed bug #73471 (PHP freezes with AppendIterator). (jhdxr)

Expand Down
7 changes: 4 additions & 3 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2110,9 +2110,10 @@ static PHP_METHOD(PDOStatement, debugDumpParams)
RETURN_FALSE;
}

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

php_stream_printf(out, "Params: %d\n",
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0);
Expand Down
40 changes: 40 additions & 0 deletions ext/pdo/tests/bug_69356.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
PDO Common: Bug #69356 (PDOStatement::debugDumpParams() truncates query)
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';

$db = PDOTest::factory();
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$stmt = $db->query("
SELECT '
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).
This is a debug function, which dump directly the data on the normal output.
Tip:
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).
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.
'
");
var_dump($stmt->debugDumpParams());
?>
--EXPECT--
SQL: [835]
SELECT '
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).
This is a debug function, which dump directly the data on the normal output.
Tip:
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).
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.
'

Params: 0
NULL

0 comments on commit 08089f0

Please sign in to comment.