Click here to Skip to main content
15,888,803 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Unable to stop SQL injection errors. Pin
Richard Deeming29-May-15 9:14
mveRichard Deeming29-May-15 9:14 
GeneralRe: Unable to stop SQL injection errors. Pin
Sascha Lefèvre29-May-15 12:55
professionalSascha Lefèvre29-May-15 12:55 
QuestionHow to get my "wp_nav_menu()" function working Pin
Truck5328-May-15 16:34
Truck5328-May-15 16:34 
QuestionHost Windows Class Library in PHP Pin
Jassim Rahma27-May-15 0:49
Jassim Rahma27-May-15 0:49 
QuestionMessage Removed Pin
22-May-15 4:28
Antonio Guedes22-May-15 4:28 
QuestionOpening an existing project in WordPress Pin
indian14321-May-15 21:21
indian14321-May-15 21:21 
AnswerRe: Opening an existing project in WordPress Pin
User 171649221-May-15 22:11
professionalUser 171649221-May-15 22:11 
QuestionImproper Neutralization of special elements used in an sql command Pin
Stephen Holdorf12-May-15 10:09
Stephen Holdorf12-May-15 10:09 
This is very similar to a previous post but with different code.

I have to eliminate a SQL injection error from within a method. Now, with only minor modifications this error must be eliminated. Here is the description from the scan:

Attack vector: system_data.system.data.IDbCommand.ExecuteReader
Description: The database query contains a sql injection flaw. The call to system_data_dll.System.Data.IDbCommand.ExecuteReader constructs a dynamic sql query using a variable derived from user-supplied input. An attacker could exploit this flaw to execute arbitrary sql queries against the database. ExecuteReader was called on the command object, which contains tainted data. The tainted data originated from earlier calls to system_data_dll.data.common.dbcommand.executereader, System_web_dll.system.web.httprequest.get_params, system_web_dll.data.common.dbadapter_fill, system_data_dll.system.data.common.dbwommand.executescarar and system_web_dll.system.web.httprequest.get_form

Code:

C#
protected DataTable ExecuteDataTable(DbCommand command, ParamData[] pDataArr)
{
    DataTable returnValue = null;
    try
    {

        if (_connection == null)
            OpenConnection();
        else
        {
            if (_connection.State == ConnectionState.Closed)
                OpenConnection();
        }

        command.Connection = _connection;
        command.CommandType = CommandType.Text;
        command.CommandTimeout = 12000;

        //add Parameter
        for (int i = 0; i < pDataArr.Length; i++)
        {
            DbParameter parameter = command.CreateParameter();
            parameter.ParameterName = pDataArr[i].pName;
            parameter.DbType = pDataArr[i].pDataType;
            parameter.Value = pDataArr[i].pValue;
            command.Parameters.Add(parameter);
        }

        // Create a DataTable
        returnValue = new DataTable();

        DbDataReader reader;
        reader = command.ExecuteReader();

        using (reader)
        {
            // Fill DataTable
            returnValue.Load(reader, LoadOption.OverwriteChanges);
        }

        reader.Close();

        if (!KeepAlive && _connection.State == ConnectionState.Open)
        {
            CloseConnection();
        }
    }
    catch (Exception e)
    {
        if (e is EntryPointNotFoundException)
            throw e;
        _iserror = true;
        LogBLL bll = new LogBLL();
        bll.WriteErrorLog(e);
    }

    pDataArr = null;

    return returnValue;
}


Thanks in advance!

modified 12-May-15 17:16pm.

AnswerRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 10:33
professionalSascha Lefèvre12-May-15 10:33 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Steve Holdorf12-May-15 12:38
Steve Holdorf12-May-15 12:38 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 12:54
professionalSascha Lefèvre12-May-15 12:54 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Steve Holdorf12-May-15 13:01
Steve Holdorf12-May-15 13:01 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 13:17
professionalSascha Lefèvre12-May-15 13:17 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Steve Holdorf12-May-15 14:14
Steve Holdorf12-May-15 14:14 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 14:54
professionalSascha Lefèvre12-May-15 14:54 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Steve Holdorf12-May-15 15:34
Steve Holdorf12-May-15 15:34 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 15:44
professionalSascha Lefèvre12-May-15 15:44 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Stephen Holdorf13-May-15 8:00
Stephen Holdorf13-May-15 8:00 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre13-May-15 9:53
professionalSascha Lefèvre13-May-15 9:53 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
PIEBALDconsult12-May-15 11:15
mvePIEBALDconsult12-May-15 11:15 
QuestionSQL Injection error. Pin
Stephen Holdorf12-May-15 9:43
Stephen Holdorf12-May-15 9:43 
AnswerRe: SQL Injection error. Pin
Sascha Lefèvre12-May-15 10:22
professionalSascha Lefèvre12-May-15 10:22 
AnswerRe: SQL Injection error. Pin
Richard Deeming13-May-15 1:38
mveRichard Deeming13-May-15 1:38 
GeneralRe: SQL Injection error. Pin
Stephen Holdorf20-May-15 3:24
Stephen Holdorf20-May-15 3:24 
QuestionAuthorize.net PayPal Option Pin
jkirkerx11-May-15 12:24
professionaljkirkerx11-May-15 12:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.