File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/semmle/code/java/frameworks/apache
test/library-tests/frameworks/apache-commons-lang3 Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -427,6 +427,15 @@ private class ApacheStrBuilderModel extends SummaryModelCsv {
427427 }
428428}
429429
430+ /**
431+ * An Apache Commons-Lang StrBuilder method that returns `this`.
432+ */
433+ private class ApacheStrBuilderFluentMethod extends FluentMethod {
434+ ApacheStrBuilderFluentMethod ( ) {
435+ this .getReturnType ( ) .( RefType ) .hasQualifiedName ( "org.apache.commons.lang3.text" , "StrBuilder" )
436+ }
437+ }
438+
430439/**
431440 * Taint-propagating models for `WordUtils`.
432441 */
Original file line number Diff line number Diff line change @@ -128,6 +128,20 @@ void test() throws Exception {
128128 StrBuilder sb72 = new StrBuilder (); sb72 .append (taint ()); sink (sb72 .toCharArray (0 , 0 )); // $hasTaintFlow
129129 StrBuilder sb73 = new StrBuilder (); sb73 .append (taint ()); sink (sb73 .toStringBuffer ()); // $hasTaintFlow
130130 StrBuilder sb74 = new StrBuilder (); sb74 .append (taint ()); sink (sb74 .toStringBuilder ()); // $hasTaintFlow
131+
132+ // Tests for fluent methods (those returning `this`):
133+
134+ StrBuilder fluentTest = new StrBuilder ();
135+ sink (fluentTest .append ("Harmless" ).append (taint ()).append ("Also harmless" ).toString ()); // $hasTaintFlow
136+
137+ StrBuilder fluentBackflowTest = new StrBuilder ();
138+ fluentBackflowTest .append ("Harmless" ).append (taint ()).append ("Also harmless" );
139+ sink (fluentBackflowTest .toString ()); // $hasTaintFlow
140+
141+ // Test the case where the fluent method contributing taint is at the end of a statement:
142+ StrBuilder fluentBackflowTest2 = new StrBuilder ();
143+ fluentBackflowTest2 .append ("Harmless" ).append (taint ());
144+ sink (fluentBackflowTest2 .toString ()); // $hasTaintFlow
131145 }
132146
133147}
You can’t perform that action at this time.
0 commit comments