fix PDO::quote api when input string contain a NUL ASCII character

This commit is contained in:
v-kaywon 2017-09-21 15:59:54 -07:00
parent 75c03f05d3
commit 57a41d71e9
2 changed files with 31 additions and 2 deletions

View file

@ -1463,7 +1463,7 @@ int pdo_sqlsrv_dbh_quote( _Inout_ pdo_dbh_t* dbh, _In_reads_(unquoted_len) const
if ( encoding == SQLSRV_ENCODING_UTF8 ) {
quotes_needed = 3;
}
for ( size_t index = 0; index < unquoted_len && unquoted[ index ] != '\0'; ++index ) {
for ( size_t index = 0; index < unquoted_len; ++index ) {
if ( unquoted[ index ] == '\'' ) {
++quotes_needed;
}
@ -1480,7 +1480,7 @@ int pdo_sqlsrv_dbh_quote( _Inout_ pdo_dbh_t* dbh, _In_reads_(unquoted_len) const
// insert initial quote
( *quoted )[ out_current++ ] = '\'';
for ( size_t index = 0; index < unquoted_len && unquoted[ index ] != '\0'; ++index ) {
for ( size_t index = 0; index < unquoted_len; ++index ) {
if ( unquoted[ index ] == '\'' ) {
( *quoted )[ out_current++ ] = '\'';
( *quoted )[ out_current++ ] = '\'';

View file

@ -0,0 +1,29 @@
--TEST--
Test the PDO::quote() method.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try
{
$connection = connect();
//$connection->setAttribute( PDO::SQLSRV_ATTR_DIRECT_QUERY, PDO::SQLSRV_ENCODING_SYSTEM );
$str = "XX\0XX";
print("Original: " . str_replace("\0", "{NUL}", $str) . "\n");
$str = $connection->quote($str);
print("Quoted: " . str_replace("\0", "{NUL}", $str) . "\n");
}
catch( PDOException $e ) {
die("Connection error: " . $e->getMessage());
}
?>
--EXPECT--
Original: XX{NUL}XX
Quoted: 'XX{NUL}XX'