/* goodG2B() - use GoodSource and BadSink */ public void goodG2BSink(Vector<StringBuilder> dataVector) throws Throwable { StringBuilder data = dataVector.remove(2); /* POTENTIAL FLAW: data could be null */ String stringTrimmed = data.toString().trim(); IO.writeLine(stringTrimmed); }
/* goodB2G() - use BadSource and GoodSink */ public void goodB2GSink(Vector<StringBuilder> dataVector) throws Throwable { StringBuilder data = dataVector.remove(2); /* FIX: explicit check for null */ if (data != null) { String stringTrimmed = data.toString().trim(); IO.writeLine(stringTrimmed); } }
/* goodB2G() - use badsource and goodsink */ public void goodB2G_sink() throws Throwable { StringBuilder data = CWE476_NULL_Pointer_Dereference__StringBuilder_68a.data; /* FIX: validate that data is non-null */ if (data != null) { IO.writeLine("" + data.length()); } else { IO.writeLine("data is null"); } }
/* goodB2G() - use badsource and goodsink by changing the conditions on the for statements */ private void goodB2G() throws Throwable { StringBuilder data; /* POTENTIAL FLAW: Initialize, but do not use data */ data = new StringBuilder("Good"); for (int for_index_j = 0; for_index_j < 0; for_index_j++) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ /* POTENTIAL FLAW: Do not use the variable */ /* do nothing */ ; /* empty statement needed for some flow variants */ } for (int for_index_k = 0; for_index_k < 1; for_index_k++) { /* FIX: Use data */ IO.writeLine(data.toString()); } }
/* goodG2B() - use goodsource and badsink */ public void goodG2B_sink() throws Throwable { StringBuilder data = CWE476_NULL_Pointer_Dereference__StringBuilder_68a.data; /* POTENTIAL FLAW: null dereference will occur if data is null */ IO.writeLine("" + data.length()); }
public void action(StringBuilder data) throws Throwable { /* FIX: Use data without over-writing its value */ IO.writeLine(data.toString()); }