Esempio n. 1
0
        public override void Bad()
        {
            double data;

            data = double.MinValue; /* Initialize data */
            /* get environment variable ADD */
            /* FLAW: Read data from an environment variable */
            {
                string stringNumber = Environment.GetEnvironmentVariable("ADD");
                if (stringNumber != null) // avoid NPD incidental warnings
                {
                    try
                    {
                        data = double.Parse(stringNumber.Trim());
                    }
                    catch (FormatException exceptNumberFormat)
                    {
                        IO.Logger.Log(NLog.LogLevel.Warn, exceptNumberFormat, "Number format exception parsing data from string");
                    }
                }
            }
            Dictionary <int, double> dataDictionary = new Dictionary <int, double>();

            dataDictionary.Add(0, data);
            dataDictionary.Add(1, data);
            dataDictionary.Add(2, data);
            CWE197_Numeric_Truncation_Error__double_Environment_to_byte_74b.BadSink(dataDictionary);
        }
Esempio n. 2
0
        /* goodG2B() - use goodsource and badsink */
        private static void GoodG2B()
        {
            double data;

            /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */
            data = 2;
            Dictionary <int, double> dataDictionary = new Dictionary <int, double>();

            dataDictionary.Add(0, data);
            dataDictionary.Add(1, data);
            dataDictionary.Add(2, data);
            CWE197_Numeric_Truncation_Error__double_Environment_to_byte_74b.GoodG2BSink(dataDictionary);
        }