/* goodG2B() - use goodsource and badsink */ private void GoodG2B() { string data; while (true) { data = ""; /* init data */ /* FIX: Read data from the console using ReadLine() */ try { /* POTENTIAL FLAW: Read data from the console using ReadLine */ data = Console.ReadLine(); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, "Error with stream reading", exceptIO); } break; } if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* uses badsource and badsink - see how tools report flaws that don't always occur */ public override void Bad() { string data; if (IO.StaticReturnsTrueOrFalse()) { /* FLAW: Set data to a hardcoded string */ data = "7e5tc4s3"; } else { data = ""; /* init data */ /* FIX: Read data from the console using ReadLine() */ try { /* POTENTIAL FLAW: Read data from the console using ReadLine */ data = Console.ReadLine(); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, "Error with stream reading", exceptIO); } } if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* GoodG2B2() - use goodsource and badsink by reversing statements in if */ private void GoodG2B2() { string data; if (privateFive == 5) { data = ""; /* init data */ /* FIX: Read data from the console using ReadLine() */ try { /* POTENTIAL FLAW: Read data from the console using ReadLine */ data = Console.ReadLine(); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, "Error with stream reading", exceptIO); } } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run * but ensure data is inititialized before the Sink to avoid compiler errors */ data = null; } if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(string data) { if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
public override void Action(string data) { if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
private void GoodG2BSink() { string data = dataGoodG2B; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B() - use goodsource and badsink */ private static void GoodG2B() { string data = CWE259_Hard_Coded_Password__NetworkCredential_61b.GoodG2BSource(); if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
public override void Bad() { string data = CWE259_Hard_Coded_Password__NetworkCredential_61b.BadSource(); if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(Dictionary <int, string> dataDictionary) { string data = dataDictionary[2]; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(CWE259_Hard_Coded_Password__NetworkCredential_67a.Container dataContainer) { string data = dataContainer.containerOne; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
public static void BadSink(string[] dataArray) { string data = dataArray[2]; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(LinkedList <string> dataLinkedList) { string data = dataLinkedList.Last.Value; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
public static void BadSink() { string data = CWE259_Hard_Coded_Password__NetworkCredential_68a.data; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* uses badsource and badsink */ public override void Bad() { string data; /* FLAW: Set data to a hardcoded string */ data = "7e5tc4s3"; if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
public override void Bad() { string data; badPrivate = true; data = Bad_source(); if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B1() - use goodsource and badsink by setting the variable to false instead of true */ private void GoodG2B1() { string data; goodG2B1_private = false; data = GoodG2B1_source(); if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* uses badsource and badsink */ public override void Bad() { string data; if (privateFive == 5) { /* FLAW: Set data to a hardcoded string */ data = "7e5tc4s3"; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run * but ensure data is inititialized before the Sink to avoid compiler errors */ data = null; } if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } }
/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(byte[] dataSerialized) { try { string data; var binForm = new BinaryFormatter(); using (var memStream = new MemoryStream()) { memStream.Write(dataSerialized, 0, dataSerialized.Length); memStream.Seek(0, SeekOrigin.Begin); data = (string)binForm.Deserialize(memStream); } if (data != null) { /* POTENTIAL FLAW: data used as password in NetworkCredential() */ NetworkCredential credentials = new NetworkCredential("user", data, "domain"); IO.WriteLine(credentials.ToString()); } } catch (SerializationException exceptSerialize) { IO.Logger.Log(NLog.LogLevel.Warn, "SerializationException in deserialization", exceptSerialize); } }