Files
codeql/csharp/ql/test/query-tests/Security Features/CWE-078/StoredCommandInjection.cs
2021-07-01 16:09:11 +02:00

29 lines
790 B
C#

using System;
using System.Data.SqlClient;
using System.Diagnostics;
namespace Test
{
class StoredCommandInjection
{
public void Test()
{
using (SqlConnection connection = new SqlConnection(""))
{
connection.Open();
SqlCommand customerCommand = new SqlCommand("SELECT * FROM customers", connection);
SqlDataReader customerReader = customerCommand.ExecuteReader();
while (customerReader.Read())
{
// BAD: Read from database, and use it to directly execute a command
Process.Start("foo.exe", "/c " + customerReader.GetString(1));
}
customerReader.Close();
}
}
}
}