Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello team,

please help me with this Sql Injection flaw in veracode and refer below code.

source code:

flaws @ both com.CommandText = cmdText;

C#
try
                {
                    connOle.Open();
                    OleDbCommand com = connOle.CreateCommand();

                    string cmdText = "DROP TABLE Report";

                    com.CommandText = cmdText;
                    com.ExecuteNonQuery();//flaw at this line

                    cmdText = "CREATE TABLE Report (Datum Text,VG_UG Text,NameVN Text,VstNr Integer,Sti Text,ArtEnt Text,ArtPr Text,Prov float)";
                    com.CommandText = cmdText;//flaw at this line

                    com.ExecuteNonQuery();

                    int i=0;
                    foreach(Calc calc in ar)
                    {
Posted
Comments
[no name] 16-Jul-15 7:16am    
You would need to ask veracode why their software is flagging these issues.

That has nothing at all to do with SQL injection: it's just a simple string creating a table.

However, not all systems support a TEXT datatype: you may need to use NVARCHAR instead - but without knowing exactly what your OLEDB is connecting to, we can't say exactly.

Start by putting that code into a try-catch block and looking in the debugger at exactly what error message is being generated. It could be that the table exists already, or any of loads of other errors.
 
Share this answer
 
Not sure what you're trying to do but you cannot create table like that. In order to create a table you need to specify proper data types for each column and so on. Have a look at the syntax[^] (if SQL Server)

Having that said, it makes even less sense to first drop the table and then create it. Somehow this looks like you're trying to empty the table. If that is your goal, use either DELETE[^] or TRUNCATE TABLE[^]. But even then remember that if this is a multi user database, other people see the changes you've made as soon as they are committed...

EDIT

The first statement most likely fails on the first time since you don't have a table to drop...

But as said it's not common at all to create or drop permanent tables on-the-fly
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900