Fix potential StackOverFlowError on regexp

This commit is contained in:
Blinkingor 2020-01-28 10:28:37 +01:00
parent 660041636a
commit 1e390984c1
2 changed files with 123 additions and 8 deletions

View File

@ -2,22 +2,22 @@ package datadog.trace.instrumentation.trace_annotation;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType; import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.named;
import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import datadog.trace.agent.tooling.Instrumenter; import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.Config; import datadog.trace.api.Config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/** /**
* TraceConfig Instrumentation does not extend Default. * TraceConfig Instrumentation does not extend Default.
* *
@ -42,16 +42,29 @@ public class TraceConfigInstrumentation implements Instrumenter {
+ PACKAGE_CLASS_NAME_REGEX + PACKAGE_CLASS_NAME_REGEX
+ "\\[" + "\\["
+ METHOD_LIST_REGEX + METHOD_LIST_REGEX
+ "\\]\\s*;?\\s*"; + "\\]";
private final Map<String, Set<String>> classMethodsToTrace; private final Map<String, Set<String>> classMethodsToTrace;
private boolean validateConfigString(String configString) {
for (String clazz : configString.split(";")) {
if (!clazz.matches(CONFIG_FORMAT)) {
return false;
}
}
return true;
}
public TraceConfigInstrumentation() { public TraceConfigInstrumentation() {
final String configString = Config.get().getTraceMethods(); this(Config.get().getTraceMethods());
}
public TraceConfigInstrumentation(final String configString) {
if (configString == null || configString.trim().isEmpty()) { if (configString == null || configString.trim().isEmpty()) {
classMethodsToTrace = Collections.emptyMap(); classMethodsToTrace = Collections.emptyMap();
} else if (!configString.matches(CONFIG_FORMAT)) { } else if (!validateConfigString(configString)) {
log.warn( log.warn(
"Invalid trace method config '{}'. Must match 'package.Class$Name[method1,method2];*'.", "Invalid trace method config '{}'. Must match 'package.Class$Name[method1,method2];*'.",
configString); configString);

File diff suppressed because one or more lines are too long