/* goodB2G1() - use badsource and goodsink by setting the static variable to false instead of true */ private void GoodB2G1() { int count = 0; count = int.MinValue; /* Initialize count */ /* Read data using a listening tcp connection */ { TcpListener listener = null; /* Read data using a listening tcp connection */ try { listener = new TcpListener(IPAddress.Parse("10.10.1.10"), 39543); listener.Start(); using (TcpClient tcpConn = listener.AcceptTcpClient()) { /* read input from socket */ using (StreamReader sr = new StreamReader(tcpConn.GetStream())) { /* POTENTIAL FLAW: Read count using a listening tcp connection */ string stringNumber = sr.ReadLine(); if (stringNumber != null) // avoid NPD incidental warnings { try { count = int.Parse(stringNumber.Trim()); } catch (FormatException exceptNumberFormat) { IO.Logger.Log(NLog.LogLevel.Warn, exceptNumberFormat, "Number format exception parsing count from string"); } } } } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error with stream reading"); } finally { try { if (listener != null) { listener.Stop(); } } catch (SocketException se) { IO.Logger.Log(NLog.LogLevel.Warn, se, "Error closing TcpListener"); } } } goodB2G1PublicStatic = false; CWE400_Uncontrolled_Resource_Consumption__Listen_tcp_for_loop_22b.GoodB2G1Sink(count); }