Skip to content

Commit 407adcb

Browse files
committed
Make new tests + change to after
1 parent 4d3d99c commit 407adcb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

dd-java-agent/agent-iast/src/main/java/com/datadog/iast/propagation/StringModuleImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ public void onStringValueOf(Object param, @Nonnull String result) {
833833

834834
@Override
835835
public void onStringBuilderSetLength(@Nonnull CharSequence self, int length) {
836-
if (self.length() <= length) {
836+
if (self.length() != length) {
837837
return;
838838
}
839839
final IastContext ctx = IastContext.Provider.get();

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/propagation/StringModuleTest.groovy

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,26 +1436,32 @@ class StringModuleTest extends IastModuleImplTestBase {
14361436
taintFormat(result, taintedObject.getRanges()) == "==>my_input<=="
14371437
}
14381438
1439-
void 'onStringBuilderSetLength empty or string not changed after setLength (#self, #length)'() {
1439+
void 'onStringBuilderSetLength is empty or different lengths (#self, #length)'() {
14401440
given:
1441-
self?.setLength(length)
1441+
self?.setLength(self.length())
14421442
14431443
when:
14441444
module.onStringBuilderSetLength(self, length)
14451445
14461446
then:
1447+
mockCalls * tracer.activeSpan() >> null
14471448
0 * _
14481449
14491450
where:
1450-
self | length
1451-
sb() | 0
1452-
sb("not_changed") | 10
1451+
self | length | mockCalls
1452+
sb("123") | 2 | 0
1453+
sb() | 0 | 1
14531454
}
14541455
14551456
void 'onStringBuilderSetLength (#input, #length)'() {
14561457
final taintedObjects = ctx.getTaintedObjects()
14571458
def self = addFromTaintFormat(taintedObjects, input)
1458-
final result = self.toString().substring(0, length)
1459+
if (self instanceof StringBuilder) {
1460+
((StringBuilder) self).setLength(length)
1461+
} else if (self instanceof StringBuffer) {
1462+
((StringBuffer) self).setLength(length)
1463+
}
1464+
final result = self.toString()
14591465
14601466
when:
14611467
module.onStringBuilderSetLength(self, length)

0 commit comments

Comments
 (0)