/* goodB2G() - use BadSource and GoodSink */ private static void GoodB2G() { ulong data; /* init data */ data = 0; /* POTENTIAL FLAW: Read data from console with ReadLine*/ try { string stringNumber = Console.ReadLine(); if (stringNumber != null) { data = ulong.Parse(stringNumber.Trim()); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, "Error with stream reading", exceptIO); } catch (FormatException exceptNumberFormat) { IO.Logger.Log(NLog.LogLevel.Warn, "Error with number parsing", exceptNumberFormat); } LinkedList <ulong> dataLinkedList = new LinkedList <ulong>(); dataLinkedList.AddLast(data); dataLinkedList.AddLast(data); dataLinkedList.AddLast(data); CWE190_Integer_Overflow__UInt64_console_readLine_multiply_73b.GoodB2GSink(dataLinkedList); }
/* goodG2B() - use GoodSource and BadSink */ private static void GoodG2B() { ulong data; /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */ data = 2; LinkedList <ulong> dataLinkedList = new LinkedList <ulong>(); dataLinkedList.AddLast(data); dataLinkedList.AddLast(data); dataLinkedList.AddLast(data); CWE190_Integer_Overflow__UInt64_console_readLine_multiply_73b.GoodG2BSink(dataLinkedList); }