-
Notifications
You must be signed in to change notification settings - Fork 275
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
Perf: Stop creating parameter prefixed names #1829
Merged
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -4877,7 +4877,7 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi | |
SqlParameter sqlParameter = rpc.userParams[index]; | ||
Debug.Assert(sqlParameter != null, "sqlParameter should not be null."); | ||
|
||
if (sqlParameter.ParameterNameFixed.Equals(parameterName, StringComparison.Ordinal)) | ||
if (SqlParameter.ParameterNamesEqual(sqlParameter.ParameterName, parameterName, StringComparison.Ordinal)) | ||
{ | ||
Debug.Assert(sqlParameter.CipherMetadata == null, "param.CipherMetadata should be null."); | ||
sqlParameter.HasReceivedMetadata = true; | ||
|
@@ -6235,7 +6235,7 @@ internal void OnReturnValue(SqlReturnValue rec, TdsParserStateObject stateObj) | |
{ | ||
if (rec.tdsType != TdsEnums.SQLBIGVARBINARY) | ||
{ | ||
throw SQL.InvalidDataTypeForEncryptedParameter(thisParam.ParameterNameFixed, rec.tdsType, TdsEnums.SQLBIGVARBINARY); | ||
throw SQL.InvalidDataTypeForEncryptedParameter(thisParam.GetPrefixedParameterName(), rec.tdsType, TdsEnums.SQLBIGVARBINARY); | ||
} | ||
|
||
// Decrypt the ciphertext | ||
|
@@ -6265,7 +6265,7 @@ internal void OnReturnValue(SqlReturnValue rec, TdsParserStateObject stateObj) | |
} | ||
catch (Exception e) | ||
{ | ||
throw SQL.ParamDecryptionFailed(thisParam.ParameterNameFixed, null, e); | ||
throw SQL.ParamDecryptionFailed(thisParam.GetPrefixedParameterName(), null, e); | ||
} | ||
} | ||
else | ||
|
@@ -6458,7 +6458,11 @@ private SqlParameter GetParameterForOutputValueExtraction(SqlParameterCollection | |
{ | ||
thisParam = parameters[i]; | ||
// searching for Output or InputOutput or ReturnValue with matching name | ||
if (thisParam.Direction != ParameterDirection.Input && thisParam.Direction != ParameterDirection.ReturnValue && paramName == thisParam.ParameterNameFixed) | ||
if ( | ||
thisParam.Direction != ParameterDirection.Input && | ||
thisParam.Direction != ParameterDirection.ReturnValue && | ||
SqlParameter.ParameterNamesEqual(paramName, thisParam.ParameterName,StringComparison.Ordinal) | ||
) | ||
{ | ||
foundParam = true; | ||
break; // found it | ||
|
@@ -6846,11 +6850,11 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto | |
|
||
// Find the return value parameter (if any). | ||
SqlParameter returnValueParameter = null; | ||
foreach (SqlParameter parameter in parameters) | ||
foreach (SqlParameter param in parameters) | ||
{ | ||
if (parameter.Direction == ParameterDirection.ReturnValue) | ||
if (param.Direction == ParameterDirection.ReturnValue) | ||
{ | ||
returnValueParameter = parameter; | ||
returnValueParameter = param; | ||
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. Why not keep the full name? |
||
break; | ||
} | ||
} | ||
|
@@ -6859,7 +6863,8 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto | |
// EXEC @returnValue = moduleName [parameters] | ||
if (returnValueParameter != null) | ||
{ | ||
execStatement.AppendFormat(@"{0}=", returnValueParameter.ParameterNameFixed); | ||
SqlParameter.AppendPrefixedParameterName(execStatement, returnValueParameter.ParameterName); | ||
execStatement.Append('='); | ||
} | ||
|
||
execStatement.Append(ParseAndQuoteIdentifier(storedProcedureName, false)); | ||
|
@@ -6870,6 +6875,7 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto | |
// Append the first parameter | ||
int index = 0; | ||
int count = parameters.Count; | ||
SqlParameter parameter; | ||
if (count > 0) | ||
{ | ||
// Skip the return value parameters. | ||
|
@@ -6880,16 +6886,20 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto | |
|
||
if (index < count) | ||
{ | ||
parameter = parameters[index]; | ||
// Possibility of a SQL Injection issue through parameter names and how to construct valid identifier for parameters. | ||
// Since the parameters comes from application itself, there should not be a security vulnerability. | ||
// Also since the query is not executed, but only analyzed there is no possibility for elevation of priviledge, but only for | ||
// incorrect results which would only affect the user that attempts the injection. | ||
execStatement.AppendFormat(@" {0}={0}", parameters[index].ParameterNameFixed); | ||
execStatement.Append(' '); | ||
SqlParameter.AppendPrefixedParameterName(execStatement, parameter.ParameterName); | ||
execStatement.Append('='); | ||
SqlParameter.AppendPrefixedParameterName(execStatement, parameter.ParameterName); | ||
|
||
// InputOutput and Output parameters need to be marked as such. | ||
if ( | ||
parameters[index].Direction == ParameterDirection.Output || | ||
parameters[index].Direction == ParameterDirection.InputOutput | ||
parameter.Direction == ParameterDirection.Output || | ||
parameter.Direction == ParameterDirection.InputOutput | ||
) | ||
{ | ||
execStatement.AppendFormat(@" OUTPUT"); | ||
|
@@ -6903,14 +6913,18 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto | |
// Append the rest of parameters | ||
for (; index < count; index++) | ||
{ | ||
if (parameters[index].Direction != ParameterDirection.ReturnValue) | ||
parameter = parameters[index]; | ||
if (parameter.Direction != ParameterDirection.ReturnValue) | ||
{ | ||
execStatement.AppendFormat(@", {0}={0}", parameters[index].ParameterNameFixed); | ||
execStatement.Append(", "); | ||
SqlParameter.AppendPrefixedParameterName(execStatement, parameter.ParameterName); | ||
execStatement.Append('='); | ||
SqlParameter.AppendPrefixedParameterName(execStatement, parameter.ParameterName); | ||
|
||
// InputOutput and Output parameters need to be marked as such. | ||
if ( | ||
parameters[index].Direction == ParameterDirection.Output || | ||
parameters[index].Direction == ParameterDirection.InputOutput | ||
parameter.Direction == ParameterDirection.Output || | ||
parameter.Direction == ParameterDirection.InputOutput | ||
) | ||
{ | ||
execStatement.AppendFormat(@" OUTPUT"); | ||
|
@@ -6942,9 +6956,10 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete | |
|
||
// add our separator for the ith parameter | ||
if (fAddSeparator) | ||
{ | ||
paramList.Append(','); | ||
|
||
paramList.Append(sqlParam.ParameterNameFixed); | ||
} | ||
SqlParameter.AppendPrefixedParameterName(paramList, sqlParam.ParameterName); | ||
|
||
MetaType mt = sqlParam.InternalMetaType; | ||
|
||
|
@@ -6953,7 +6968,7 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete | |
|
||
// paragraph above doesn't seem to be correct. Server won't find the type | ||
// if we don't provide a fully qualified name | ||
paramList.Append(" "); | ||
paramList.Append(' '); | ||
if (mt.SqlDbType == SqlDbType.Udt) | ||
{ | ||
string fullTypeName = sqlParam.UdtTypeName; | ||
|
@@ -6967,7 +6982,7 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete | |
string typeName = sqlParam.TypeName; | ||
if (ADP.IsEmpty(typeName)) | ||
{ | ||
throw SQL.MustSetTypeNameForParam(mt.TypeName, sqlParam.ParameterNameFixed); | ||
throw SQL.MustSetTypeNameForParam(mt.TypeName, sqlParam.GetPrefixedParameterName()); | ||
} | ||
paramList.Append(ParseAndQuoteIdentifier(typeName, false /* is not UdtTypeName*/)); | ||
|
||
|
Oops, something went wrong.
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 not keep the full name?
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.
Because a variable with that name is created and used later in this scope. I don't want to explicitly re-use the same variable because it can leave opportunity for errors to creep in with casual refactorings in future. So I renamed the foreach version because it has the lower number of uses. Same with the other one you noted below.