/* goodB2G() - use badsource and goodsink */ private static void GoodB2G(HttpRequest req, HttpResponse resp) { string data = CWE89_SQL_Injection__Web_Get_Cookies_Web_ExecuteNonQuery_61b.GoodB2GSource(req, resp); int? result = null; try { using (SqlConnection dbConnection = IO.GetDBConnection()) { dbConnection.Open(); using (SqlCommand goodSqlCommand = new SqlCommand(null, dbConnection)) { goodSqlCommand.CommandText = "insert into users (status) values ('updated') where name=@name"; /* FIX: Use prepared statement and ExecuteNonQuery (properly) */ SqlParameter nameParam = new SqlParameter("@name", SqlDbType.VarChar, 0); nameParam.Value = data; goodSqlCommand.Parameters.Add(nameParam); goodSqlCommand.Prepare(); result = goodSqlCommand.ExecuteNonQuery(); if (result != null) { IO.WriteLine("Name, " + data + ", updated successfully"); } else { IO.WriteLine("Unable to update records for user: "******"Error getting database connection", exceptSql); } }