/* goodB2G() - use badsource and goodsink */ private static void GoodB2G(HttpRequest req, HttpResponse resp) { string data = CWE89_SQL_Injection__Web_Connect_tcp_ExecuteScalar_61b.GoodB2GSource(req, resp); try { using (SqlConnection dbConnection = IO.GetDBConnection()) { dbConnection.Open(); using (SqlCommand goodSqlCommand = new SqlCommand(null, dbConnection)) { /* FIX: Use prepared statement and concatenate ExecuteScalar() (properly) */ SqlParameter nameParam = new SqlParameter("@name", SqlDbType.VarChar, 100); nameParam.Value = data; goodSqlCommand.CommandText += "select * from users where name=@name"; goodSqlCommand.Prepare(); object firstCol = goodSqlCommand.ExecuteScalar(); if (firstCol != null) { IO.WriteLine(firstCol.ToString()); /* Use ResultSet in some way */ } } } } catch (SqlException exceptSql) { IO.Logger.Log(NLog.LogLevel.Warn, "Error getting database connection", exceptSql); } }