8000 Increase IAST propagation to StringBuilder subSequence by Mariovido · Pull Request #8026 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Increase IAST propagation to StringBui 8000 lder subSequence #8026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for stringbuilder subsequence
  • Loading branch information
Mariovido committed Nov 27, 2024
commit 216bac7f16f0a6b99a11a231bd85cbd2205febe4
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,21 @@ public static String afterSubstring(
}
return result;
}

@CallSite.After("java.lang.CharSequence java.lang.StringBuilder.subSequence(int, int)")
public static CharSequence afterSubSequence(
@CallSite.This final CharSequence self,
@CallSite.Argument final int beginIndex,
@CallSite.Argument final int endIndex,
@CallSite.Return final CharSequence result) {
final StringModule module = InstrumentationBridge.STRING;
if (module != null) {
try {
module.onStringSubSequence(self, beginIndex, endIndex, result);
} catch (final Throwable e) {
module.onUnexpectedException("afterSubSequence threw", e);
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,40 +210,41 @@ class StringBuilderCallSiteTest extends AgentTestRunner {
sbf('012345') | 1 | '12345'
}

def 'test string builder substring with endIndex call site'() {
def 'test string builder/buffer #method with endIndex call site'() {
setup:
final iastModule = Mock(StringModule)
InstrumentationBridge.registerIastModule(iastModule)

when:
final result = TestStringBuilderSuite.substring(param, beginIndex, endIndex)
final result = suite."$method"(param, beginIndex, endIndex)

then:
result == expected
1 * iastModule.onStringSubSequence(param, beginIndex, endIndex, expected)
0 * _

where:
param | beginIndex | endIndex | expected
sb('012345') | 1 | 5 | '1234'
suite | method | param | beginIndex | endIndex | expected
new TestStringBuilderSuite() | "substring" | sb('012345') | 1 | 5 | '1234'
new TestStringBufferSuite() | "substring" | sbf('012345') | 1 | 5 | '1234'
}

def 'test string buffer substring with endIndex call site'() {
def 'test string builder/buffer #method with endIndex call site'() {
setup:
final iastModule = Mock(StringModule)
InstrumentationBridge.registerIastModule(iastModule)

when:
final result = TestStringBufferSuite.substring(param, beginIndex, endIndex)
final result = suite."$method"(param, beginIndex, endIndex)

then:
result == expected
1 * iastModule.onStringSubSequence(param, beginIndex, endIndex, expected)
0 * _

where:
param | beginIndex | endIndex | expected
sbf('012345') | 1 | 5 | '1234'
suite | method | param | beginIndex | endIndex | expected
new TestStringBuilderSuite() | "subSequence" | sb('012345') | 1 | 5 | '1234'
}

private static class BrokenToString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ public static String substring(StringBuilder self, int beginIndex) {
LOGGER.debug("After string builder substring {}", result);
return result;
}

public static CharSequence subSequence(StringBuilder self, int beginIndex, int endIndex) {
LOGGER.debug("Before string builder subSequence {} from {} to {}", self, beginIndex, endIndex);
final CharSequence result = self.subSequence(beginIndex, endIndex);
LOGGER.debug("After string builder subSequence {}", result);
return result;
}
}
0