-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for issues found by Semmle #1011
Changes from 10 commits
680ddd9
821692c
87948c2
a485029
3ce5e27
d86f1b9
f7fe1e7
2497950
1b108df
cbdc84c
574c7a6
0cb5b09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As shown in #905 please add test cases with strings that consist of punctuation and/or space characters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't really have anything to do with escaping braces though - the code changes only affect braces. Should there be a separate test for nonalphanumeric characters in strings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok you can leave that. I think we have a backlog item created already |
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code seems to assume
value_len >= 2
? But what ifvalue_len
is 0? See my first comment above...In fact, consider using strchr() for parsing the string, something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the last call to strchr may overshoot the end of the buffer. But I will try it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @david-puglielli please double check whether this might happen, fix the formatting of this section and add an equivalent test for pdo_sqlsrv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to get some idea from the deleted tests in #905