Skip to content

Commit a15be2f

Browse files
authored
Merge branch 'master' into alejandro.gonzalez/APPSEC-61873-4-undertow-play
2 parents c4da39c + d4d2069 commit a15be2f

27 files changed

Lines changed: 1454 additions & 0 deletions

.github/g2j-migrated-modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
buildSrc/call-site-instrumentation-plugin
99
components/json
10+
dd-java-agent/instrumentation/sofarpc/sofarpc-5.0
1011
dd-trace-api

dd-java-agent/instrumentation/java/java-io-1.8/src/main/java/datadog/trace/instrumentation/java/lang/FilesCallSite.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public static void beforeCopyFromStream(@CallSite.Argument(1) @Nullable final Pa
4343
}
4444
}
4545

46+
@CallSite.Before(
47+
"java.nio.file.Path java.nio.file.Files.copy(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption[])")
48+
public static void beforeCopyPathToPath(
49+
@CallSite.Argument(0) @Nullable final Path source,
50+
@CallSite.Argument(1) @Nullable final Path target) {
51+
if (source != null) {
52+
FileIORaspHelper.INSTANCE.beforeFileLoaded(source.toString());
53+
}
54+
if (target != null) {
55+
FileIORaspHelper.INSTANCE.beforeFileWritten(target.toString());
56+
}
57+
}
58+
4659
@CallSite.Before(
4760
"java.nio.file.Path java.nio.file.Files.move(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption[])")
4861
public static void beforeMove(@CallSite.Argument(1) @Nullable final Path target) {
@@ -51,6 +64,13 @@ public static void beforeMove(@CallSite.Argument(1) @Nullable final Path target)
5164
}
5265
}
5366

67+
@CallSite.Before("long java.nio.file.Files.copy(java.nio.file.Path, java.io.OutputStream)")
68+
public static void beforeCopyToStream(@CallSite.Argument(0) @Nullable final Path source) {
69+
if (source != null) {
70+
FileIORaspHelper.INSTANCE.beforeFileLoaded(source.toString());
71+
}
72+
}
73+
5474
// ===================== READ =====================
5575

5676
@CallSite.Before(

dd-java-agent/instrumentation/java/java-io-1.8/src/test/groovy/datadog/trace/instrumentation/java/io/FilesCallSiteTest.groovy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ class FilesCallSiteTest extends BaseIoRaspCallSiteTest {
102102
1 * helper.beforeFileWritten(path.toString())
103103
}
104104

105+
void 'test RASP Files.copy path to path fires beforeFileLoaded on source and beforeFileWritten on target'() {
106+
setup:
107+
final helper = Mock(FileIORaspHelper)
108+
FileIORaspHelper.INSTANCE = helper
109+
final source = newFile('test_rasp_copy_src.txt').toPath()
110+
final target = temporaryFolder.resolve('test_rasp_copy_path_dst.txt')
111+
112+
when:
113+
TestFilesSuite.copyPathToPath(source, target)
114+
115+
then:
116+
1 * helper.beforeFileLoaded(source.toString())
117+
1 * helper.beforeFileWritten(target.toString())
118+
}
119+
120+
void 'test RASP Files.copy path to OutputStream fires beforeFileLoaded on source'() {
121+
setup:
122+
final helper = Mock(FileIORaspHelper)
123+
FileIORaspHelper.INSTANCE = helper
124+
final source = newFile('test_rasp_copy_stream_src.txt').toPath()
125+
126+
when:
127+
TestFilesSuite.copyToStream(source, new ByteArrayOutputStream())
128+
129+
then:
130+
1 * helper.beforeFileLoaded(source.toString())
131+
0 * helper.beforeFileWritten(_)
132+
}
133+
105134
void 'test RASP Files.move'() {
106135
setup:
107136
final helper = Mock(FileIORaspHelper)

dd-java-agent/instrumentation/java/java-io-1.8/src/test/java/foo/bar/TestFilesSuite.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public static BufferedWriter newBufferedWriterDefaultCharset(
5757
return Files.newBufferedWriter(path, options);
5858
}
5959

60+
public static Path copyPathToPath(
61+
final Path source, final Path target, final CopyOption... options) throws IOException {
62+
return Files.copy(source, target, options);
63+
}
64+
65+
public static long copyToStream(final Path source, final OutputStream out) throws IOException {
66+
return Files.copy(source, out);
67+
}
68+
6069
public static Path move(final Path source, final Path target, final CopyOption... options)
6170
throws IOException {
6271
return Files.move(source, target);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
muzzle {
2+
pass {
3+
group = "com.alipay.sofa"
4+
module = "sofa-rpc-all"
5+
versions = "[5.0.0,)"
6+
assertInverse = true
7+
}
8+
}
9+
10+
apply from: "$rootDir/gradle/java.gradle"
11+
12+
addTestSuiteForDir('latestDepTest', 'test')
13+
14+
configurations.testRuntimeClasspath {
15+
resolutionStrategy.force "com.google.guava:guava:32.1.3-jre"
16+
}
17+
18+
dependencies {
19+
compileOnly group: "com.alipay.sofa", name: "sofa-rpc-all", version: "5.6.0"
20+
21+
testImplementation group: "com.alipay.sofa", name: "sofa-rpc-all", version: "5.14.2"
22+
// JAX-RS annotations required for the REST protocol test interface (@Path, @GET, etc.)
23+
testImplementation group: "javax.ws.rs", name: "javax.ws.rs-api", version: "2.1.1"
24+
// Required so that GrpcServerModule / GrpcClientModule are discovered via ServiceLoader
25+
// in SofaRpcTripleWithGrpcForkedTest.
26+
testImplementation project(':dd-java-agent:instrumentation:grpc-1.5')
27+
testImplementation group: "io.grpc", name: "grpc-netty", version: "1.53.0"
28+
testImplementation group: "io.grpc", name: "grpc-core", version: "1.53.0"
29+
testImplementation group: "io.grpc", name: "grpc-stub", version: "1.53.0"
30+
testImplementation group: "com.google.protobuf", name: "protobuf-java", version: "3.25.3"
31+
testImplementation group: "com.alibaba", name: "fastjson", version: "1.2.83"
32+
testImplementation group: "com.google.guava", name: "guava", version: "32.1.3-jre"
33+
34+
latestDepTestImplementation group: "com.alipay.sofa", name: "sofa-rpc-all", version: "+"
35+
}

0 commit comments

Comments
 (0)