Skip to content

Commit

Permalink
Check if jvm options or system properties are being passed as command
Browse files Browse the repository at this point in the history
line options (and being ignored).
  • Loading branch information
mgm3746 committed Oct 10, 2024
1 parent cef531b commit aa24b1a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 2 deletions.
71 changes: 71 additions & 0 deletions src/main/java/org/github/krashpad/domain/jdk/FatalErrorLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,27 @@ && getOsVersion() == OsVersion.RHEL7 && getRhelVersion() != null && !getRhelVers
if (isMultithreadedGc() && getActiveProcessorCount() > 0 && getActiveProcessorCount() < 2) {
analysis.add(Analysis.ERROR_MULTITHREADED_COLLECTOR_LT_2_CPU);
}
// Check for jvm options and system properties being passed as command line options
if (getJavaCommand() != null) {
String args = null;
// remove beginning and ending jar references
String regex = "^([^ ]+\\.jar)?(.+?(?=-jar))-jar .+$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(getJavaCommand());
if (matcher.find()) {
args = matcher.group(2);
}
if (args != null) {
JvmContext jvmContext = new JvmContext(args);
JvmOptions jvmOptions = new JvmOptions(jvmContext);
if (jvmOptions.getOptions().size() > 0) {
analysis.add(Analysis.ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS);
}
if (jvmOptions.getSystemProperties().size() > 0) {
analysis.add(Analysis.ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES);
}
}
}
}

/**
Expand Down Expand Up @@ -1807,6 +1828,56 @@ public List<String[]> getAnalysis() {
a.add(new String[] { item.getKey(), event.getLogEntry() });
}
}
} else if (item.getKey().equals(Analysis.ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS.toString())) {
StringBuffer s = new StringBuffer(item.getValue());
JvmContext jvmContext = new JvmContext(getJavaCommand());
JvmOptions jvmOptions = new JvmOptions(jvmContext);
Iterator<Entry<String, ArrayList<String>>> iteratorOptions = jvmOptions.getOptions().entrySet()
.iterator();
boolean punctuate = false;
while (iteratorOptions.hasNext()) {
Entry<String, ArrayList<String>> option = iteratorOptions.next();
if (!option.getKey().equals("undefined")) {
ArrayList<String> opt = option.getValue();
Iterator<String> iteratorOption = opt.iterator();
while (iteratorOption.hasNext()) {
if (punctuate) {
s.append(" ");
}
s.append(iteratorOption.next());
punctuate = true;
}
}
}
s.append(".");
a.add(new String[] { item.getKey(), s.toString() });
} else if (item.getKey().equals(Analysis.ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES.toString())) {
StringBuffer s = new StringBuffer(item.getValue());
String args = null;
// remove beginning and ending jar references
String regex = "^([^ ]+\\.jar)?(.+?(?=-jar))-jar .+$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(getJavaCommand());
if (matcher.find()) {
args = matcher.group(2);
}
if (args != null) {
JvmContext jvmContext = new JvmContext(args);
JvmOptions jvmOptions = new JvmOptions(jvmContext);
ArrayList<String> systemProperties = jvmOptions.getSystemProperties();
Iterator<String> iterator = systemProperties.iterator();
boolean punctuate = false;
while (iterator.hasNext()) {
String systemProperty = iterator.next();
if (punctuate) {
s.append(" ");
}
s.append(systemProperty);
punctuate = true;
}
s.append(".");
a.add(new String[] { item.getKey(), s.toString() });
}
} else if (item.getKey().equals(Analysis.ERROR_OOME_RLIMIT_MAX_MAP_COUNT.toString())) {
StringBuffer s = new StringBuffer(item.getValue());
if (getGcPreciousLogWarning() != null) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/github/krashpad/util/jdk/Analysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public enum Analysis {
*/
ERROR_ITEXT_IO("error.itext.io"),

/**
* Property key for JVM options being passed as command line options (and being ignored).
*/
ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS("error.java.command.has.jvm.options"),

/**
* Property key for system properties being passed as command line options (and being ignored).
*/
ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES("error.java.command.has.system.properties"),

/**
* Property key for an unknown JDK version.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/org/github/krashpad/analysis.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ error.gregoriancalendar.computetime=crash in java.util.GregorianCalendar.compute
error.hashmap=Crash in java.util.HashMap. HashMap is not threadsafe. Check if the crash is due to multiple threads concurrently reading/writing to the HashMap.
error.inspecting.top.of.stack=
error.itext.io=Crash in StubRoutines from iText I/O due to a threading issue in the iText library where a file is attempting to be read before it is completely written to disk. Reference: https://access.redhat.com/solutions/5665601.
error.java.command.has.jvm.options=The following JVM options are being passed as command line arguments and being ignored:
error.java.command.has.system.properties=The following system properties are being passed as command line arguments and being ignored:
error.jdk.version.unknown=Unknown JDK version.
error.jdk.version.unsupported=Unsupported JDK version. krashpad targets JDK8+. Analysis may be incomplete (e.g. unidentified log lines).
error.jdk8.deflater.contention=There is an application or operations invalid use case resulting in an attempt to modify a file while Java has it open. A workaround to avoid the crash is to disable memory mapping in ZipFile with -Dsun.zip.disableMemoryMapping=true (at the cost of some loss in performance), or upgrade to JDK 11. References: (1) https://access.redhat.com/solutions/2620091. (2) https://bugs.openjdk.org/browse/JDK-8145260.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void testOops() {
assertTrue(JdkUtil.identifyEventType(logLine, priorEvent) == JdkUtil.LogEventType.REGISTER_TO_MEMORY_MAPPING,
JdkUtil.LogEventType.REGISTER_TO_MEMORY_MAPPING.toString() + " not identified.");
}

@Test
void testParseLogLine() {
RegisterToMemoryMapping priorLogEvent = new RegisterToMemoryMapping("Register to memory mapping:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void testDependencies() {
JdkUtil.identifyEventType(logLine, priorLogEvent),
JdkUtil.LogEventType.STACK_SLOT_TO_MEMORY_MAPPING.toString() + " not identified.");
}

@Test
void testError() {
StackSlotToMemoryMapping priorLogEvent = new StackSlotToMemoryMapping("Stack slot to memory mapping:");
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/github/krashpad/util/jdk/TestAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,30 @@ void testItextIoStubRoutinesJintDisjointArrayCopyRandomAccessFileOrArray() {
Analysis.ERROR_ITEXT_IO + " analysis not identified.");
}

@Test
void testJavaCommandHasJvmArgss() {
FatalErrorLog fel = new FatalErrorLog();
String jvm_args = "java_command: /deployments/quarkus-run.jar -XX:-UseParallelGC -XX:+UseSerialGC "
+ "-Djava.util.logging.manager=org.jboss.logmanager.LogManager -jar /deployments/quarkus-run.jar";
VmArguments event = new VmArguments(jvm_args);
fel.getVmArguments().add(event);
fel.doAnalysis();
assertTrue(fel.hasAnalysis(Analysis.ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS.getKey()),
Analysis.ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS + " analysis not identified.");
assertEquals(
"The following JVM options are being passed as command line arguments and being ignored: "
+ "-XX:-UseParallelGC -XX:+UseSerialGC.",
fel.getAnalysisLiteral(Analysis.ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS.getKey()),
Analysis.ERROR_JAVA_COMMAND_HAS_JVM_OPTIONS + " analysis literal not correct.");
assertTrue(fel.hasAnalysis(Analysis.ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES.getKey()),
Analysis.ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES + " analysis not identified.");
assertEquals(
"The following system properties are being passed as command line arguments and being ignored: "
+ "-Djava.util.logging.manager=org.jboss.logmanager.LogManager.",
fel.getAnalysisLiteral(Analysis.ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES.getKey()),
Analysis.ERROR_JAVA_COMMAND_HAS_SYSTEM_PROPERTIES + " analysis literal not correct.");
}

@Test
void testJavaSrSignum() {
FatalErrorLog fel = new FatalErrorLog();
Expand Down

0 comments on commit aa24b1a

Please sign in to comment.