示例#1
0
        /* goodB2G1() - use badsource and goodsink by setting the static variable to false instead of true */
        private void GoodB2G1(HttpRequest req, HttpResponse resp)
        {
            string data = null;

            data = ""; /* Initialize data */
            /* Read data from a database */
            {
                try
                {
                    /* setup the connection */
                    using (SqlConnection connection = IO.GetDBConnection())
                    {
                        connection.Open();
                        /* prepare and execute a (hardcoded) query */
                        using (SqlCommand command = new SqlCommand(null, connection))
                        {
                            command.CommandText = "select name from users where id=0";
                            command.Prepare();
                            using (SqlDataReader dr = command.ExecuteReader())
                            {
                                /* POTENTIAL FLAW: Read data from a database query SqlDataReader */
                                data = dr.GetString(1);
                            }
                        }
                    }
                }
                catch (SqlException exceptSql)
                {
                    IO.Logger.Log(NLog.LogLevel.Warn, exceptSql, "Error with SQL statement");
                }
            }
            goodB2G1PublicStatic = false;
            CWE89_SQL_Injection__Web_Database_CommandText_22b.GoodB2G1Sink(data, req, resp);
        }
示例#2
0
        /* goodG2B() - use goodsource and badsink */
        private void GoodG2B(HttpRequest req, HttpResponse resp)
        {
            string data = null;

            /* FIX: Use a hardcoded string */
            data = "foo";
            goodG2BPublicStatic = true;
            CWE89_SQL_Injection__Web_Database_CommandText_22b.GoodG2BSink(data, req, resp);
        }