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

Commit

Permalink
Merge pull request #670 from ezimuel/fix/655
Browse files Browse the repository at this point in the history
Fix for 655 issue - ZF2015-08 breaks binary data
  • Loading branch information
froschdesign committed Feb 15, 2016
2 parents 4b46967 + 70d8aba commit ebf608f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
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);
}
}

0 comments on commit ebf608f

Please sign in to comment.