@@ -4881,7 +4881,7 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi
48814881 SqlParameter sqlParameter = rpc . userParams [ index ] ;
48824882 Debug . Assert ( sqlParameter != null , "sqlParameter should not be null." ) ;
48834883
4884- if ( sqlParameter . ParameterNameFixed . Equals ( parameterName , StringComparison . Ordinal ) )
4884+ if ( SqlParameter . ParameterNamesEqual ( sqlParameter . ParameterName , parameterName , StringComparison . Ordinal ) )
48854885 {
48864886 Debug . Assert ( sqlParameter . CipherMetadata == null , "param.CipherMetadata should be null." ) ;
48874887 sqlParameter . HasReceivedMetadata = true ;
@@ -6239,7 +6239,7 @@ internal void OnReturnValue(SqlReturnValue rec, TdsParserStateObject stateObj)
62396239 {
62406240 if ( rec. tdsType != TdsEnums. SQLBIGVARBINARY)
62416241 {
6242- throw SQL. InvalidDataTypeForEncryptedParameter( thisParam. ParameterNameFixed , rec. tdsType, TdsEnums. SQLBIGVARBINARY) ;
6242+ throw SQL. InvalidDataTypeForEncryptedParameter( thisParam. GetPrefixedParameterName ( ) , rec. tdsType, TdsEnums. SQLBIGVARBINARY) ;
62436243 }
62446244
62456245 // Decrypt the ciphertext
@@ -6269,7 +6269,7 @@ internal void OnReturnValue(SqlReturnValue rec, TdsParserStateObject stateObj)
62696269 }
62706270 catch ( Exception e )
62716271 {
6272- throw SQL . ParamDecryptionFailed ( thisParam . ParameterNameFixed , null , e ) ;
6272+ throw SQL . ParamDecryptionFailed ( thisParam . GetPrefixedParameterName ( ) , null , e ) ;
62736273 }
62746274 }
62756275 else
@@ -6462,7 +6462,11 @@ private SqlParameter GetParameterForOutputValueExtraction(SqlParameterCollection
64626462 {
64636463 thisParam = parameters [ i ] ;
64646464 // searching for Output or InputOutput or ReturnValue with matching name
6465- if ( thisParam . Direction != ParameterDirection . Input && thisParam . Direction != ParameterDirection . ReturnValue && paramName == thisParam . ParameterNameFixed )
6465+ if (
6466+ thisParam . Direction != ParameterDirection . Input &&
6467+ thisParam . Direction != ParameterDirection . ReturnValue &&
6468+ SqlParameter . ParameterNamesEqual ( paramName , thisParam . ParameterName , StringComparison . Ordinal )
6469+ )
64666470 {
64676471 foundParam = true ;
64686472 break ; // found it
@@ -6850,11 +6854,11 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto
68506854
68516855 // Find the return value parameter (if any).
68526856 SqlParameter returnValueParameter = null ;
6853- foreach ( SqlParameter parameter in parameters )
6857+ foreach ( SqlParameter param in parameters )
68546858 {
6855- if ( parameter . Direction == ParameterDirection . ReturnValue )
6859+ if ( param . Direction == ParameterDirection . ReturnValue )
68566860 {
6857- returnValueParameter = parameter ;
6861+ returnValueParameter = param ;
68586862 break ;
68596863 }
68606864 }
@@ -6863,7 +6867,8 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto
68636867 // EXEC @returnValue = moduleName [parameters]
68646868 if ( returnValueParameter != null )
68656869 {
6866- execStatement . AppendFormat ( @"{0}=" , returnValueParameter . ParameterNameFixed ) ;
6870+ SqlParameter . AppendPrefixedParameterName ( execStatement , returnValueParameter . ParameterName ) ;
6871+ execStatement . Append ( '=' ) ;
68676872 }
68686873
68696874 execStatement . Append ( ParseAndQuoteIdentifier ( storedProcedureName , false ) ) ;
@@ -6874,6 +6879,7 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto
68746879 // Append the first parameter
68756880 int index = 0 ;
68766881 int count = parameters . Count ;
6882+ SqlParameter parameter ;
68776883 if ( count > 0 )
68786884 {
68796885 // Skip the return value parameters.
@@ -6884,16 +6890,20 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto
68846890
68856891 if ( index < count )
68866892 {
6893+ parameter = parameters [ index ] ;
68876894 // Possibility of a SQL Injection issue through parameter names and how to construct valid identifier for parameters.
68886895 // Since the parameters comes from application itself, there should not be a security vulnerability.
68896896 // Also since the query is not executed, but only analyzed there is no possibility for elevation of priviledge, but only for
68906897 // incorrect results which would only affect the user that attempts the injection.
6891- execStatement . AppendFormat ( @" {0}={0}" , parameters [ index ] . ParameterNameFixed ) ;
6898+ execStatement . Append ( ' ' ) ;
6899+ SqlParameter . AppendPrefixedParameterName ( execStatement , parameter . ParameterName ) ;
6900+ execStatement . Append ( '=' ) ;
6901+ SqlParameter . AppendPrefixedParameterName ( execStatement , parameter . ParameterName ) ;
68926902
68936903 // InputOutput and Output parameters need to be marked as such.
68946904 if (
6895- parameters [ index ] . Direction == ParameterDirection . Output ||
6896- parameters [ index ] . Direction == ParameterDirection . InputOutput
6905+ parameter . Direction == ParameterDirection . Output ||
6906+ parameter . Direction == ParameterDirection . InputOutput
68976907 )
68986908 {
68996909 execStatement . AppendFormat ( @" OUTPUT" ) ;
@@ -6907,14 +6917,18 @@ private SqlParameter BuildStoredProcedureStatementForColumnEncryption(string sto
69076917 // Append the rest of parameters
69086918 for ( ; index < count ; index ++ )
69096919 {
6910- if ( parameters [ index ] . Direction != ParameterDirection . ReturnValue )
6920+ parameter = parameters [ index ] ;
6921+ if ( parameter . Direction != ParameterDirection . ReturnValue )
69116922 {
6912- execStatement . AppendFormat ( @", {0}={0}" , parameters [ index ] . ParameterNameFixed ) ;
6923+ execStatement . Append ( ", " ) ;
6924+ SqlParameter . AppendPrefixedParameterName ( execStatement , parameter . ParameterName ) ;
6925+ execStatement . Append ( '=' ) ;
6926+ SqlParameter . AppendPrefixedParameterName ( execStatement , parameter . ParameterName ) ;
69136927
69146928 // InputOutput and Output parameters need to be marked as such.
69156929 if (
6916- parameters [ index ] . Direction == ParameterDirection . Output ||
6917- parameters [ index ] . Direction == ParameterDirection . InputOutput
6930+ parameter . Direction == ParameterDirection . Output ||
6931+ parameter . Direction == ParameterDirection . InputOutput
69186932 )
69196933 {
69206934 execStatement . AppendFormat ( @" OUTPUT" ) ;
@@ -6946,9 +6960,10 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete
69466960
69476961 // add our separator for the ith parameter
69486962 if ( fAddSeparator )
6963+ {
69496964 paramList . Append ( ',' ) ;
6950-
6951- paramList . Append ( sqlParam . ParameterNameFixed ) ;
6965+ }
6966+ SqlParameter . AppendPrefixedParameterName ( paramList , sqlParam . ParameterName ) ;
69526967
69536968 MetaType mt = sqlParam . InternalMetaType ;
69546969
@@ -6957,7 +6972,7 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete
69576972
69586973 // paragraph above doesn't seem to be correct. Server won't find the type
69596974 // if we don't provide a fully qualified name
6960- paramList . Append ( " " ) ;
6975+ paramList . Append ( ' ' ) ;
69616976 if ( mt . SqlDbType == SqlDbType . Udt )
69626977 {
69636978 string fullTypeName = sqlParam . UdtTypeName ;
@@ -6971,7 +6986,7 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete
69716986 string typeName = sqlParam . TypeName ;
69726987 if ( ADP . IsEmpty ( typeName ) )
69736988 {
6974- throw SQL . MustSetTypeNameForParam ( mt . TypeName , sqlParam . ParameterNameFixed ) ;
6989+ throw SQL . MustSetTypeNameForParam ( mt . TypeName , sqlParam . GetPrefixedParameterName ( ) ) ;
69756990 }
69766991 paramList . Append ( ParseAndQuoteIdentifier ( typeName , false /* is not UdtTypeName*/ ) ) ;
69776992
0 commit comments