Fix #71943: dblib_handle_quoter needs to allocate an extra byte

This commit is contained in:
Adam Baratz 2016-04-01 11:23:35 -04:00 committed by Anatol Belski
parent 9a65c69c62
commit 9fcfc18ca9
2 changed files with 26 additions and 2 deletions

View File

@ -170,7 +170,7 @@ static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu
*
*/
*quotedlen = (unquotedlen * 2) + 2; /* 2 chars per byte +2 for "0x" prefix */
q = *quoted = emalloc(*quotedlen);
q = *quoted = emalloc(*quotedlen+1); /* Add byte for terminal null */
*q++ = '0';
*q++ = 'x';
@ -181,7 +181,7 @@ static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu
} else {
/* Alpha/Numeric Quoting */
*quotedlen += 2; /* +2 for opening, closing quotes */
q = *quoted = emalloc(*quotedlen);
q = *quoted = emalloc(*quotedlen+1); /* Add byte for terminal null */
*q++ = '\'';
for (i=0;i<unquotedlen;i++) {

View File

@ -0,0 +1,24 @@
--TEST--
PDO_DBLIB: Ensure quote function returns expected results
--SKIPIF--
<?php
if (!extension_loaded('pdo_dblib')) die('skip not loaded');
require dirname(__FILE__) . '/config.inc';
?>
--FILE--
<?php
require dirname(__FILE__) . '/config.inc';
var_dump($db->quote(true, PDO::PARAM_BOOL));
var_dump($db->quote(false, PDO::PARAM_BOOL));
var_dump($db->quote(42, PDO::PARAM_INT));
var_dump($db->quote(null, PDO::PARAM_NULL));
var_dump($db->quote('\'', PDO::PARAM_STR));
var_dump($db->quote('foo', PDO::PARAM_STR));
?>
--EXPECT--
string(3) "'1'"
string(2) "''"
string(4) "'42'"
string(2) "''"
string(4) "''''"
string(5) "'foo'"