Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Prevent null byte-based SQL injection
Browse files Browse the repository at this point in the history
- Added code to escape null bytes using addcslashes.
  • Loading branch information
weierophinney committed Sep 16, 2014
1 parent 1fdb9e5 commit c72c9d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Adapter/Platform/SqlServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function quoteValue($value)
'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support '
. 'can introduce security vulnerabilities in a production environment.'
);
$value = addcslashes($value, "\000\032");
return '\'' . str_replace('\'', '\'\'', $value) . '\'';
}

Expand Down
9 changes: 9 additions & 0 deletions test/Adapter/Platform/SqlServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,13 @@ public function testSetDriver()
$driver = new Pdo(array('pdodriver' => 'sqlsrv'));
$this->platform->setDriver($driver);
}

public function testPlatformQuotesNullByteCharacter()
{
$err = set_error_handler(function () {} );
$string = "1\0";
$value = $this->platform->quoteValue($string);
set_error_handler($err);
$this->assertEquals("'1\\000'", $value);
}
}

0 comments on commit c72c9d0

Please sign in to comment.