Skip to main content
public int ExecuteNonQuery(string query, SqlParameter[] parameters)
{
    using (SqlCommand command = CreateCommand(query, parameters))
    {
        int rowsAffected = command.ExecuteNonQuery();
        log.Debug("rows affected: {0}", rowsAffected);
        return rowsAffected;
    }
}
 public int ExecuteNonQuery(string query, SqlParameter[] parameters)
 {
     using (SqlCommand command = CreateCommand(query, parameters))
     {
         int rowsAffected = command.ExecuteNonQuery();
         log.Debug("rows affected: {0}", rowsAffected);
         return rowsAffected;
     }
 }
private SqlCommand CreateCommand(string commandText, SqlParameter[] parameters)
        {
            SqlCommand retVal = this.connection.CreateCommand();
            retVal.CommandText = commandText;
            retVal.CommandTimeout = this.commandsTimeout;
            retVal.Parameters.AddRange(parameters);
            return retVal;
        }
public int ExecuteNonQuery(string query, SqlParameter[] parameters)
{
    using (SqlCommand command = CreateCommand(query, parameters))
    {
        int rowsAffected = command.ExecuteNonQuery();
        log.Debug("rows affected: {0}", rowsAffected);
        return rowsAffected;
    }
}
private SqlCommand CreateCommand(string commandText, SqlParameter[] parameters)
        {
            SqlCommand retVal = this.connection.CreateCommand();
            retVal.CommandText = commandText;
            retVal.CommandTimeout = this.commandsTimeout;
            retVal.Parameters.AddRange(parameters);
            return retVal;
        }
 public int ExecuteNonQuery(string query, SqlParameter[] parameters)
 {
     using (SqlCommand command = CreateCommand(query, parameters))
     {
         int rowsAffected = command.ExecuteNonQuery();
         log.Debug("rows affected: {0}", rowsAffected);
         return rowsAffected;
     }
 }
private SqlCommand CreateCommand(string commandText, SqlParameter[] parameters)
 {
     SqlCommand retVal = this.connection.CreateCommand();
     retVal.CommandText = commandText;
     retVal.CommandTimeout = this.commandsTimeout;
     retVal.Parameters.AddRange(parameters);
     return retVal;
}
deleted 12 characters in body; edited tags; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

SQL Injection - Validating user supplied input

I was assigned a task to fix the SQL injection flaw reported by a code analysis tool and. I am not the original author of the code and. I do have fair amount of knowledge onam fairly knowledgeable with SQL.

1 public int ExecuteNonQuery(string query, SqlParameter[] parameters)
2 {
3   using (SqlCommand command = CreateCommand(query, parameters))
4   {
5       int rowsAffected = command.ExecuteNonQuery();
6       log.Debug("rows affected: {0}", rowsAffected);
7       return rowsAffected;
8   }
9 }
public int ExecuteNonQuery(string query, SqlParameter[] parameters)
{
    using (SqlCommand command = CreateCommand(query, parameters))
    {
        int rowsAffected = command.ExecuteNonQuery();
        log.Debug("rows affected: {0}", rowsAffected);
        return rowsAffected;
    }
}

My questions are:Is there any injection risk in this code? If yes, how do I recognize it?

  1. Is there any injection risk in this code?
  2. If yes, how do I recognize?

SQL Injection - Validating user supplied input

I was assigned a task to fix the SQL injection flaw reported by a code analysis tool and I am not the original author of the code and I do have fair amount of knowledge on SQL.

1 public int ExecuteNonQuery(string query, SqlParameter[] parameters)
2 {
3   using (SqlCommand command = CreateCommand(query, parameters))
4   {
5       int rowsAffected = command.ExecuteNonQuery();
6       log.Debug("rows affected: {0}", rowsAffected);
7       return rowsAffected;
8   }
9 }

My questions are:

  1. Is there any injection risk in this code?
  2. If yes, how do I recognize?

Validating user supplied input

I was assigned a task to fix the SQL injection flaw reported by a code analysis tool. I am not the original author of the code. I am fairly knowledgeable with SQL.

public int ExecuteNonQuery(string query, SqlParameter[] parameters)
{
    using (SqlCommand command = CreateCommand(query, parameters))
    {
        int rowsAffected = command.ExecuteNonQuery();
        log.Debug("rows affected: {0}", rowsAffected);
        return rowsAffected;
    }
}

Is there any injection risk in this code? If yes, how do I recognize it?

deleted 43 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Here is the code...

and the tool has reported the injection flaw at the line number 3. The ExecuteNonQuery is being called from so many places. 

Here is one such sample.:

Here is the CreateCommandCreateCommand code:

My questions are,:

Your help appreciated.

Here is the code...

and the tool has reported the injection flaw at the line number 3. The ExecuteNonQuery is being called from so many places. Here is one such sample.

Here is the CreateCommand code

My questions are,

Your help appreciated.

and the tool has reported the injection flaw at the line number 3. The ExecuteNonQuery is being called from so many places. 

Here is one such sample:

Here is the CreateCommand code:

My questions are:

added 424 characters in body
Source Link
NJMR
  • 161
  • 4
Loading
Source Link
NJMR
  • 161
  • 4
Loading