/* goodG2B() - use goodsource and badsink */ private static void GoodG2B() { string data; data = ""; /* Initialize data */ /* read user input from console with readLine */ try { /* FIX: Read data from the console using readLine() */ data = Console.ReadLine(); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, "Error with stream reading", exceptIO); } /* serialize data to a byte array */ byte[] dataSerialized = null; try { BinaryFormatter bf = new BinaryFormatter(); using (var ms = new MemoryStream()) { bf.Serialize(ms, data); dataSerialized = ms.ToArray(); } CWE321_Hard_Coded_Cryptographic_Key__basic_75b.GoodG2BSink(dataSerialized); } catch (SerializationException exceptSerialize) { IO.Logger.Log(NLog.LogLevel.Warn, "Serialization exception in serialization", exceptSerialize); } }
public override void Bad() { string data; /* FLAW: Set data to a hardcoded value */ data = "23 ~j;asn!@#/>as"; /* serialize data to a byte array */ byte[] dataSerialized = null; try { BinaryFormatter bf = new BinaryFormatter(); using (var ms = new MemoryStream()) { bf.Serialize(ms, data); dataSerialized = ms.ToArray(); } CWE321_Hard_Coded_Cryptographic_Key__basic_75b.BadSink(dataSerialized); } catch (SerializationException exceptSerialize) { IO.Logger.Log(NLog.LogLevel.Warn, "Serialization exception in serialization", exceptSerialize); } }