Skip to content

Commit

Permalink
Hardened logPath extraction some more
Browse files Browse the repository at this point in the history
  • Loading branch information
rx committed Feb 10, 2017
1 parent ff0222c commit bfe6732
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -35,7 +35,9 @@
*/
public class VirtualMachine implements Comparable<VirtualMachine>
{

private static final String OPT_AGENT = "-agentpath";
private static final String OPT_LOG = "logPath=";

private final String id;
private final String displayName;
private final boolean agentLoaded;
Expand Down Expand Up @@ -69,14 +71,14 @@ public boolean isAgentLoaded()
public LogSource getLogSourceFromVmArgs() throws CantReadFromSourceException
{
// Bail out if agentpath is not defined.
if (vmArgs.indexOf("-agentpath") < 0)
if (vmArgs.indexOf(OPT_AGENT) < 0)
{
return getLogSource();
}

// Extract the value of the agentpath parameter

int agentPathStart = vmArgs.indexOf("-agentpath") + "-agentpath".length();
int agentPathStart = vmArgs.indexOf(OPT_AGENT) + OPT_AGENT.length();

// TODO FIX : if the logPath contains spaces, this will cause trouble.
int agentPathEnd = vmArgs.indexOf(' ', agentPathStart);
Expand All @@ -87,14 +89,14 @@ public LogSource getLogSourceFromVmArgs() throws CantReadFromSourceException
String agentPath = vmArgs.substring(agentPathStart, agentPathEnd);

// Bail out if logPath is not defined.
if (agentPath.indexOf("logPath") < 0)
if (agentPath.indexOf(OPT_LOG) < 0)
{
return getLogSource();
}

// Extract the value of the logPath parameter

int logPathStart = agentPath.indexOf("logPath=") + "logPath=".length();
int logPathStart = agentPath.indexOf(OPT_LOG) + OPT_LOG.length();
int commaPos = agentPath.indexOf(",", logPathStart);
int spacePos = agentPath.indexOf(' ', logPathStart);
int logPathEnd = commaPos > 0 ? commaPos : (spacePos > 0 ? spacePos : agentPath.length());
Expand Down

0 comments on commit bfe6732

Please sign in to comment.