diff --git a/source/pdo_sqlsrv/pdo_dbh.cpp b/source/pdo_sqlsrv/pdo_dbh.cpp index 80a99b7f..c0a7ea4f 100644 --- a/source/pdo_sqlsrv/pdo_dbh.cpp +++ b/source/pdo_sqlsrv/pdo_dbh.cpp @@ -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++ ] = '\''; diff --git a/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt b/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt new file mode 100644 index 00000000..91ca72be --- /dev/null +++ b/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test the PDO::quote() method. +--SKIPIF-- + +--FILE-- +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' \ No newline at end of file