Skip to content

Commit

Permalink
[pinpoint-apm#10358] Ensure className not null for module permission
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed Oct 13, 2023
1 parent 5a00bcb commit 9115084
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 3 deletions.
38 changes: 38 additions & 0 deletions agent-testweb/closed-module-testlib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
33 changes: 33 additions & 0 deletions agent-testweb/closed-module-testlib/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-agent-testweb</artifactId>
<version>2.6.0-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-closed-module-testlib</artifactId>
<packaging>jar</packaging>

<properties>
<jdk.version>11</jdk.version>
<jdk.home>${env.JAVA_11_HOME}</jdk.home>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2023 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpointdemo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* @author youngjin.kim2
*/
public class ClosedService {

private final ExecutorService executor = Executors.newFixedThreadPool(4);

public void fire() {
try {
List<Integer> data = new ArrayList<>(16);
for (int i = 0; i < 16; i++) {
data.add(i);
}
data.parallelStream()
.map(v -> parserTask(v))
.forEach(this.executor::submit);
} catch (Exception ignored) {
System.out.println("error");
}
}

private Runnable parserTask(int v) {
return () -> System.out.println(v + "^2=" + (v*v));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module pinpoint.closed.module.testlib {
exports com.navercorp.pinpointdemo;
}
38 changes: 38 additions & 0 deletions agent-testweb/closed-module-testweb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
54 changes: 54 additions & 0 deletions agent-testweb/closed-module-testweb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-agent-testweb</artifactId>
<version>2.6.0-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-closed-module-testweb</artifactId>
<packaging>jar</packaging>

<properties>
<pinpoint.agent.jvmargument>
${pinpoint.agent.default.jvmargument}
</pinpoint.agent.jvmargument>
<curator.framework.version>4.2.0</curator.framework.version>

<jdk.version>11</jdk.version>
<jdk.home>${env.JAVA_11_HOME}</jdk.home>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-closed-module-testlib</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.closedcaller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author youngjin.kim2
*/
@SpringBootApplication
public class ClosedClassCallerStarter {

public static void main(String[] args) {
SpringApplication.run(ClosedClassCallerStarter.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.closedcaller;

import com.navercorp.pinpointdemo.ClosedService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author youngjin.kim2
*/
@RestController
public class ClosedClassCallingController {

private final ClosedService closedService = new ClosedService();

@GetMapping("/closed")
public String callClosedMethod() {
this.closedService.fire();
return "called";
}

}
10 changes: 10 additions & 0 deletions agent-testweb/closed-module-testweb/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open module com.navercorp.pinpoint.closedcaller {
requires spring.web;
requires spring.context;
requires spring.beans;
requires spring.boot.autoconfigure;
requires spring.boot;
requires spring.core;

requires pinpoint.closed.module.testlib;
}
2 changes: 2 additions & 0 deletions agent-testweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<module>ning-asynchttpclient-plugin-testweb</module>
<module>okhttp-plugin-testweb</module>
<module>grpc-plugin-testweb</module>
<module>closed-module-testweb</module>
<module>closed-module-testlib</module>
</modules>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import com.navercorp.pinpoint.bootstrap.module.JavaModule;
import com.navercorp.pinpoint.bootstrap.module.JavaModuleFactory;
import com.navercorp.pinpoint.common.util.ClassUtils;
import org.apache.logging.log4j.Logger;
import com.navercorp.pinpoint.profiler.instrument.classreading.SimpleClassMetadataReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
Expand Down Expand Up @@ -59,22 +60,32 @@ public byte[] transform(Object transformedModuleObject, ClassLoader loader, Stri
if (!javaModuleFactory.isNamedModule(transformedModuleObject)) {
return transform;
}

final String className0 = ensureClassName(className, classfileBuffer);

// bootstrap-core permission
final JavaModule transformedModule = javaModuleFactory.wrapFromModule(transformedModuleObject);
addModulePermission(transformedModule, className, bootstrapModule);
addModulePermission(transformedModule, className0, bootstrapModule);


if (loader != Object.class.getClassLoader()) {
// plugin permission
final Object pluginModuleObject = getPluginModule(loader);
final JavaModule pluginModule = javaModuleFactory.wrapFromModule(pluginModuleObject);

addModulePermission(transformedModule, className, pluginModule);
addModulePermission(transformedModule, className0, pluginModule);
}
}
return transform;
}

private static String ensureClassName(String className, byte[] classfileBuffer) {
if (className != null) {
return className;
}
return SimpleClassMetadataReader.readSimpleClassMetadata(classfileBuffer).getClassName();
}

private Object getPluginModule(ClassLoader loader) {
// current internal implementation
// The plugin.jar is loaded into the unnamed module
Expand Down
Loading

0 comments on commit 9115084

Please sign in to comment.