-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed for issues found by Semmle (#1011)
* Removed unneeded constants * Fixed sqlsrv_free_stmt argument info * Fixed brace escape to avoid buffer overflow * Fixed brace escape and added test * Debugging test failure on Bamboo * Removed debugging output * Debugging test failure on Bamboo * Removed debugging output * Added more test cases * Changed range check to use strchr * Added pdo test * Fixed test and formatting
- Loading branch information
1 parent
b839ede
commit 1a2b493
Showing
8 changed files
with
165 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--TEST-- | ||
Test that right braces are escaped correctly and that error messages are correct when they're not | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
$server = 'fakeserver'; | ||
$uid = 'sa'; | ||
$password = 'fakepassword'; | ||
|
||
// If the braces are fine, then we expect the connection to fail with a login timeout error | ||
$braceError = "An unescaped right brace (}) was found"; | ||
$connError = (strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') ? "Could not open a connection to SQL Server" : "Login timeout expired"; | ||
|
||
// Every combination of one, two, three, or more right braces I can think of | ||
$testStrings = array(array("}", $braceError), | ||
array("{", $connError), | ||
array("{t}", $connError), | ||
array("{}}", $braceError), | ||
array("}}", $connError), | ||
array("}}}", $braceError), | ||
array("}}}}", $connError), | ||
array("{}}}", $connError), | ||
array("}{", $braceError), | ||
array("}{{", $braceError), | ||
array("test", $connError), | ||
array("{test}", $connError), | ||
array("{test", $connError), | ||
array("test}", $braceError), | ||
array("{{test}}", $braceError), | ||
array("{{test}", $connError), | ||
array("{{test", $connError), | ||
array("test}}", $connError), | ||
array("{test}}", $braceError), | ||
array("test}}}", $braceError), | ||
array("{test}}}", $connError), | ||
array("{test}}}}", $braceError), | ||
array("{test}}}}}", $connError), | ||
array("{test}}}}}}", $braceError), | ||
array("te}st", $braceError), | ||
array("{te}st}", $braceError), | ||
array("{te}}st}", $connError), | ||
array("{te}}}st}", $braceError), | ||
array("te}}s}t", $braceError), | ||
array("te}}s}}t", $connError), | ||
array("te}}}st", $braceError), | ||
array("te}}}}st", $connError), | ||
array("tes}}t", $connError), | ||
array("te}s}}t", $braceError), | ||
array("tes}}t}}", $connError), | ||
array("tes}}t}}}", $braceError), | ||
array("tes}t}}", $braceError), | ||
); | ||
|
||
foreach ($testStrings as $test) { | ||
|
||
try { | ||
$conn = new PDO("sqlsrv:Server=".$server.";LoginTimeout=1;", $test[0], $password); | ||
} catch (PDOException $e) { | ||
if (strpos($e->getMessage(), $test[1]) === false) { | ||
print_r("Wrong error message returned for test string ".$test[0].". Expected ".$test[1].", actual output:\n"); | ||
print_r($e->getMessage); | ||
echo "\n"; | ||
} | ||
} | ||
} | ||
|
||
echo "Done.\n"; | ||
?> | ||
--EXPECT-- | ||
Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--TEST-- | ||
Test that right braces are escaped correctly and that error messages are correct when they're not | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
$server = 'fakeserver'; | ||
$uid = 'sa'; | ||
$password = 'fakepassword'; | ||
|
||
// If the braces are fine, then we expect the connection to fail with a login timeout error | ||
$braceError = "An unescaped right brace (}) was found"; | ||
$connError = (strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') ? "Could not open a connection to SQL Server" : "Login timeout expired"; | ||
|
||
// Every combination of one, two, three, or more right braces I can think of | ||
$testStrings = array(array("}", $braceError), | ||
array("{", $connError), | ||
array("{t}", $connError), | ||
array("{}}", $braceError), | ||
array("}}", $connError), | ||
array("}}}", $braceError), | ||
array("}}}}", $connError), | ||
array("{}}}", $connError), | ||
array("}{", $braceError), | ||
array("}{{", $braceError), | ||
array("test", $connError), | ||
array("{test}", $connError), | ||
array("{test", $connError), | ||
array("test}", $braceError), | ||
array("{{test}}", $braceError), | ||
array("{{test}", $connError), | ||
array("{{test", $connError), | ||
array("test}}", $connError), | ||
array("{test}}", $braceError), | ||
array("test}}}", $braceError), | ||
array("{test}}}", $connError), | ||
array("{test}}}}", $braceError), | ||
array("{test}}}}}", $connError), | ||
array("{test}}}}}}", $braceError), | ||
array("te}st", $braceError), | ||
array("{te}st}", $braceError), | ||
array("{te}}st}", $connError), | ||
array("{te}}}st}", $braceError), | ||
array("te}}s}t", $braceError), | ||
array("te}}s}}t", $connError), | ||
array("te}}}st", $braceError), | ||
array("te}}}}st", $connError), | ||
array("tes}}t", $connError), | ||
array("te}s}}t", $braceError), | ||
array("tes}}t}}", $connError), | ||
array("tes}}t}}}", $braceError), | ||
array("tes}t}}", $braceError), | ||
); | ||
|
||
foreach ($testStrings as $test) { | ||
|
||
$conn = sqlsrv_connect($server, array('uid'=>$test[0], 'pwd'=>$password, 'LoginTimeout'=>1)); | ||
|
||
if (strpos(sqlsrv_errors()[0][2], $test[1]) === false) { | ||
print_r("Wrong error message returned for test string ".$test[0].". Expected ".$test[1].", actual output:\n"); | ||
print_r(sqlsrv_errors()); | ||
} | ||
|
||
unset($conn); | ||
} | ||
|
||
echo "Done.\n"; | ||
?> | ||
--EXPECT-- | ||
Done. |