Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Fix for 655 issue #670

Merged
merged 1 commit into from
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions library/Zend/Db/Adapter/Pdo/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ protected function _quote($value)
if (is_int($value) || is_float($value)) {
return $value;
}
// Fix for null-byte injection
$value = addcslashes($value, "\000\032");
$this->_connect();
return $this->_connection->quote($value);
}
Expand Down
15 changes: 15 additions & 0 deletions library/Zend/Db/Adapter/Pdo/Mssql.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,19 @@ public function getServerVersion()
return null;
}
}

/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (!is_int($value) && !is_float($value)) {
// Fix for null-byte injection
$value = addcslashes($value, "\000\032");
}
return parent::_quote($value);
}
}
14 changes: 14 additions & 0 deletions library/Zend/Db/Adapter/Pdo/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,18 @@ public function limit($sql, $count, $offset = 0)
return $sql;
}

/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (!is_int($value) && !is_float($value)) {
// Fix for null-byte injection
$value = addcslashes($value, "\000\032");
}
return parent::_quote($value);
}
}
11 changes: 11 additions & 0 deletions tests/Zend/Db/Adapter/Pdo/MssqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ public function testAdapterDescribeTableWithSchemaName()
$this->assertArrayHasKey('product_name', $productsTableInfo);
}

/**
* test that quote() escapes null byte character
* in a string.
*/
public function testAdapterQuoteNullByteCharacter()
{
$string = "1\0";
$value = $this->_db->quote($string);
$this->assertEquals("'1\\000'", $value);
}

public function getDriver()
{
return 'Pdo_Mssql';
Expand Down
13 changes: 11 additions & 2 deletions tests/Zend/Db/Adapter/Pdo/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,17 @@ public function testAdapterIncludesCharsetInsideGeneratedPdoDsn()
$adapter = new ZendTest_Db_Adapter_Pdo_Mysql(array('dbname' => 'foo', 'charset' => 'XYZ', 'username' => 'bar', 'password' => 'foo'));
$this->assertEquals('mysql:dbname=foo;charset=XYZ', $adapter->_dsn());
}


/**
* Test that quote() does not alter binary data
*/
public function testBinaryQuoteWithNulls()
{
$binary = pack("xxx");
$value = $this->_db->quote($binary);
$this->assertEquals('\'\0\0\0\'', $value);
}

public function getDriver()
{
return 'Pdo_Mysql';
Expand All @@ -330,4 +340,3 @@ public function _dsn()
return parent::_dsn();
}
}

11 changes: 11 additions & 0 deletions tests/Zend/Db/Adapter/Pdo/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,15 @@ protected function _testAdapterAlternateStatement($stmtClass)
$this->assertTrue($stmt instanceof $stmtClass,
'Expecting object of type ' . $stmtClass . ', got ' . get_class($stmt));
}

/**
* test that quote() escapes null byte character
* in a string.
*/
public function testAdapterQuoteNullByteCharacter()
{
$string = "1\0";
$value = $this->_db->quote($string);
$this->assertEquals("'1\\000'", $value);
}
}