-
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
Initialize output param buffer when allocating extra space #907
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
85 changes: 85 additions & 0 deletions
85
test/functional/pdo_sqlsrv/pdo_900_output_param_memory_data.phpt
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,85 @@ | ||
--TEST-- | ||
GitHub issue 900 - output parameter displays data from memory when not finalized | ||
--DESCRIPTION-- | ||
This test verifies that when there is an active resultset and output parameter not finalized, it should not show any data from client memory. This test does not work with AlwaysEncrypted because | ||
the output param is not assigned in the stored procedure. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
$size = 30; | ||
|
||
function getOutputParam($conn, $storedProcName, $dataType, $inout) | ||
{ | ||
global $size; | ||
|
||
try { | ||
$output = null; | ||
|
||
$stmt = $conn->prepare("$storedProcName @OUTPUT = :output"); | ||
// $stmt->bindParam('output', $output, PDO::PARAM_STR, $size); | ||
if ($inout) { | ||
$paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT; | ||
} else { | ||
$paramType = PDO::PARAM_STR; | ||
} | ||
$stmt->bindParam('output', $output, $paramType, $size); | ||
|
||
$stmt->execute(); | ||
|
||
// the output param should be doubled in size for wide characters | ||
// however, it should not contain any data so after trimming it | ||
// should be merely an empty string | ||
$len = strlen($output); | ||
$result = trim($output); | ||
|
||
if ($len != ($size * 2) || $result !== "" ) { | ||
echo "Unexpected output param for $dataType: "; | ||
var_dump($output); | ||
} | ||
|
||
$stmt->closeCursor(); | ||
if (!is_null($output)) { | ||
echo "Output param should be null when finalized!"; | ||
} | ||
unset($stmt); | ||
} catch (PdoException $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
} | ||
|
||
try { | ||
// This helper method sets PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION | ||
// $conn = connect(); | ||
$conn = new PDO( "sqlsrv:server=$server; Database = $databaseName", $uid, $pwd); | ||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); | ||
|
||
$dataTypes = array("VARCHAR(512)", "VARCHAR(max)", "NVARCHAR(512)", "NVARCHAR(max)"); | ||
for ($i = 0, $p = 3; $i < count($dataTypes); $i++, $p++) { | ||
// Create the stored procedure first | ||
$storedProcName = "spNullOutputParam" . $i; | ||
$procArgs = "@OUTPUT $dataTypes[$i] OUTPUT"; | ||
$procCode = "SELECT 1, 2, 3"; | ||
|
||
createProc($conn, $storedProcName, $procArgs, $procCode); | ||
getOutputParam($conn, $storedProcName, $dataTypes[$i], false); | ||
getOutputParam($conn, $storedProcName, $dataTypes[$i], true); | ||
|
||
// Drop the stored procedure | ||
dropProc($conn, $storedProcName); | ||
} | ||
|
||
echo "Done\n"; | ||
|
||
unset($conn); | ||
} catch (PdoException $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
Done |
81 changes: 81 additions & 0 deletions
81
test/functional/sqlsrv/sqlsrv_900_output_param_memory_data.phpt
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,81 @@ | ||
--TEST-- | ||
GitHub issue 900 - output parameter displays data from memory when not finalized | ||
--DESCRIPTION-- | ||
This test verifies that when there is an active resultset and output parameter not finalized, it should not show any data from client memory. This test does not work with AlwaysEncrypted because | ||
the output param is not assigned in the stored procedure. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_versions_old.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once('MsCommon.inc'); | ||
|
||
$size = 30; | ||
|
||
function getOutputParam($conn, $storedProcName, $inout, $isVarchar, $isMax) | ||
{ | ||
global $size; | ||
|
||
$output = null; | ||
$dir = ($inout)? SQLSRV_PARAM_INOUT : SQLSRV_PARAM_OUT; | ||
$dataType = ($isVarchar)? "SQLSRV_SQLTYPE_VARCHAR" : "SQLSRV_SQLTYPE_NVARCHAR"; | ||
$sqlType = ($isMax)? call_user_func($dataType, 'max') : call_user_func($dataType, $size); | ||
|
||
$stmt = sqlsrv_prepare($conn, "$storedProcName @OUTPUT = ?", array(array(&$output, $dir, null, $sqlType))); | ||
if (!$stmt) { | ||
fatalError("getOutputParam: failed when preparing to call $storedProcName"); | ||
} | ||
if (!sqlsrv_execute($stmt)) { | ||
fatalError("getOutputParam: failed to execute procedure $storedProcName"); | ||
} | ||
|
||
// The output param should be doubled in size for wide characters; | ||
// for max fields it should be the maximum anticipated size 8000. | ||
// However, it should not contain any data so after trimming it | ||
// should be merely an empty string | ||
$len = strlen($output); | ||
$expectedLen = ($isMax)? 8000 : ($size * 2); | ||
$result = trim($output); | ||
|
||
if ($len != $expectedLen || $result !== "" ) { | ||
echo "Unexpected output param for $dataType, $isMax: "; | ||
var_dump($output); | ||
} | ||
|
||
sqlsrv_next_result($stmt); | ||
if (!is_null($output)) { | ||
echo "Output param should be null when finalized!"; | ||
} | ||
} | ||
|
||
set_time_limit(0); | ||
sqlsrv_configure('WarningsReturnAsErrors', 1); | ||
|
||
$conn = connect(array("CharacterSet" => "UTF-8")); | ||
if (!$conn) { | ||
fatalError("Could not connect.\n"); | ||
} | ||
|
||
$dataTypes = array("VARCHAR(512)", "VARCHAR(max)", "NVARCHAR(512)", "NVARCHAR(max)"); | ||
for ($i = 0, $p = 3; $i < count($dataTypes); $i++, $p++) { | ||
// Create the stored procedure first | ||
$storedProcName = "spNullOutputParam" . $i; | ||
$procArgs = "@OUTPUT $dataTypes[$i] OUTPUT"; | ||
$procCode = "SELECT 1, 2, 3"; | ||
|
||
createProc($conn, $storedProcName, $procArgs, $procCode); | ||
getOutputParam($conn, $storedProcName, false, ($i < 2), ($i % 2 != 0)); | ||
getOutputParam($conn, $storedProcName, true, ($i < 2), ($i % 2 != 0)); | ||
|
||
// Drop the stored procedure | ||
dropProc($conn, $storedProcName); | ||
} | ||
|
||
echo "Done\n"; | ||
|
||
sqlsrv_close($conn); | ||
|
||
?> | ||
--EXPECT-- | ||
Done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is there no comparison to the max size of 8000 in the pdo test?
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.
good point! I should redesign the sqlsrv test to fix the size like the pdo test