From 9fb1f19aab9e4535c1c208fdd3dc0e986940b160 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 21 Aug 2017 01:15:46 +1200 Subject: Prevent PatternUtil in production --- src/org/traccar/helper/PatternUtil.java | 7 ++++++- src/org/traccar/protocol/EskyProtocolDecoder.java | 3 --- test/org/traccar/helper/PatternUtilTest.java | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index 12536eaef..1bbb166a6 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package org.traccar.helper; +import java.lang.management.ManagementFactory; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -49,6 +50,10 @@ public final class PatternUtil { public static MatchResult checkPattern(String pattern, String input) { + if (!ManagementFactory.getRuntimeMXBean().getInputArguments().toString().contains("-agentlib:jdwp")) { + throw new RuntimeException("PatternUtil usage detected"); + } + MatchResult result = new MatchResult(); for (int i = 0; i < pattern.length(); i++) { diff --git a/src/org/traccar/protocol/EskyProtocolDecoder.java b/src/org/traccar/protocol/EskyProtocolDecoder.java index c12753881..0d3dcafb2 100644 --- a/src/org/traccar/protocol/EskyProtocolDecoder.java +++ b/src/org/traccar/protocol/EskyProtocolDecoder.java @@ -55,9 +55,6 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - org.traccar.helper.PatternUtil.MatchResult matchResult = - org.traccar.helper.PatternUtil.checkPattern(PATTERN.pattern(), (String) msg); - Parser parser = new Parser(PATTERN, (String) msg); if (!parser.matches()) { return null; diff --git a/test/org/traccar/helper/PatternUtilTest.java b/test/org/traccar/helper/PatternUtilTest.java index b6b05e88c..77660078a 100644 --- a/test/org/traccar/helper/PatternUtilTest.java +++ b/test/org/traccar/helper/PatternUtilTest.java @@ -1,11 +1,13 @@ package org.traccar.helper; +import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.assertEquals; public class PatternUtilTest { - + + @Ignore @Test public void testCheckPattern() { -- cgit v1.2.3