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 {
427
427
}
428
428
}
429
429
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
+
430
439
/**
431
440
* Taint-propagating models for `WordUtils`.
432
441
*/
Original file line number Diff line number Diff line change @@ -128,6 +128,20 @@ void test() throws Exception {
128
128
StrBuilder sb72 = new StrBuilder (); sb72 .append (taint ()); sink (sb72 .toCharArray (0 , 0 )); // $hasTaintFlow
129
129
StrBuilder sb73 = new StrBuilder (); sb73 .append (taint ()); sink (sb73 .toStringBuffer ()); // $hasTaintFlow
130
130
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
131
145
}
132
146
133
147
}
You can’t perform that action at this time.
0 commit comments