Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSue Chaplain2019-04-15 07:54:56 -0400
committerGitHub2019-04-15 07:54:56 -0400
commitc469c56a594a6437a3fb03b3c68169f50031b6ae (patch)
tree99ecba22f17c5f2fec844efc3171e5f594cb6977
parent27a88638abbb7e701dd5f2b562ae0d39476b60da (diff)
parentf9c25049cf3ed3ca3015d340ba697b0cbc4ff3dc (diff)
downloadopenj9-c469c56a594a6437a3fb03b3c68169f50031b6ae.tar.gz
openj9-c469c56a594a6437a3fb03b3c68169f50031b6ae.tar.xz
openj9-c469c56a594a6437a3fb03b3c68169f50031b6ae.zip
Merge pull request #166 from paulcheeseman/option-builder-improvements
Option builders - improve quoting behaviour and detect commas
-rw-r--r--tools/xdump_option_builder.html166
-rw-r--r--tools/xtrace_option_builder.html92
2 files changed, 152 insertions, 106 deletions
diff --git a/tools/xdump_option_builder.html b/tools/xdump_option_builder.html
index ae077b5..a0d8307 100644
--- a/tools/xdump_option_builder.html
+++ b/tools/xdump_option_builder.html
@@ -616,17 +616,9 @@ function buildAndUpdateResult() {
}
// msg_filter
- var messageFilterString = document.getElementById("event_throwable_msg_filter").value;
- if (document.getElementById("event_throwable_msg_filter").disabled == false && messageFilterString != "") {
- // Escape quotes in the filter
- messageFilterString = messageFilterString.replace(/"/g, "\\\"");
-
- // Wrap the command in quotes if the entire option isn't going to be wrapped in quotes
- if (document.getElementById("wrap_in_quotes").checked) {
- resultString += ",msg_filter=" + messageFilterString;
- } else {
- resultString += ",msg_filter=\"" + messageFilterString + "\"";
- }
+ var messageFilterStringElement = document.getElementById("event_throwable_msg_filter");
+ if (messageFilterStringElement.disabled == false && messageFilterStringElement.value != "") {
+ resultString += ",msg_filter=" + messageFilterStringElement.value;
}
// range
@@ -656,15 +648,7 @@ function buildAndUpdateResult() {
if (document.getElementById("agent_tool").checked) {
var execString = document.getElementById("exec").value;
if (execString != "") {
- // Escape quotes in the command
- execString = execString.replace(/"/g, "\\\"");
-
- // Wrap the command in quotes if the entire option isn't going to be wrapped in quotes
- if (document.getElementById("wrap_in_quotes").checked) {
- resultString += ",exec=" + execString;
- } else {
- resultString += ",exec=\"" + execString + "\"";
- }
+ resultString += ",exec=" + execString;
}
// opts
@@ -708,21 +692,19 @@ function buildAndUpdateResult() {
resultString += ",file=";
var fileString = document.getElementById("file_text").value;
if (fileString != "") {
- // Escape quotes in the filename
- // (I'm not sure what sort of monster would put quotes in the filename, but hey)
- fileString = fileString.replace(/"/g, "\\\"");
-
- // Wrap the filename in quotes if the entire option isn't going to be wrapped in quotes
- if (document.getElementById("wrap_in_quotes").checked) {
- resultString += fileString;
- } else {
- resultString += "\"" + fileString + "\"";
- }
+ resultString += fileString;
}
}
// Wrap in quotes if option checked
if (document.getElementById("wrap_in_quotes").checked) {
+ // Escape backslashes
+ resultString = resultString.replace(/\\/g, "\\\\");
+
+ // Escape quotes
+ resultString = resultString.replace(/"/g, "\\\"");
+
+ // Wrap the entire result string in quotes
resultString = "\"" + resultString + "\"";
}
@@ -780,10 +762,18 @@ function buildAndUpdateResult() {
// Check that a command has been specified if the tool agent is selected
var execElement = document.getElementById("exec");
- if (document.getElementById("agent_tool").checked && execElement.value == "") {
- resultIsGreen = false;
- setErrorStyle(execElement);
- errorsHtml += "ERROR: Shell command (tool) agent is checked, but no shell command has been specified<br>";
+ if (document.getElementById("agent_tool").checked) {
+ if (execElement.value == "") {
+ resultIsGreen = false;
+ setErrorStyle(execElement);
+ errorsHtml += "ERROR: Shell command (tool) agent is checked, but no shell command has been specified<br>";
+ } else if (execElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(execElement);
+ errorsHtml += "ERROR: Invalid shell command: must not contain a comma.<br>";
+ } else {
+ unsetErrorStyle(execElement);
+ }
} else {
unsetErrorStyle(execElement);
}
@@ -798,57 +788,93 @@ function buildAndUpdateResult() {
unsetErrorStyle(toolWaitElement);
}
- // Check validity of the throwable class string
+ // Check validity of the throwable class filter. Rules:
+ // 1. Can start with a wildcard character
+ // 2. Can end with a wildcard character if no method filter is specified
+ // 3. Can contain just a single wildcard character on its own
+ // 4. Cannot contain a wildcard in any other location
+ // 5. Cannot contain a comma
+ var throwableClassHasError = false;
var throwableClassElement = document.getElementById("event_throwable_class")
if (!throwableClassElement.disabled) {
var classValue = throwableClassElement.value;
+
if (classValue.lastIndexOf("*") > 0) {
- if (classValue.lastIndexOf("*") != (classValue.length - 1)) {
- // Wildcard must be placed at the beginning and/or end of the string
- resultIsGreen = false;
- setErrorStyle(throwableClassElement);
- errorsHtml += "ERROR: Exception class filter wildcards can only be used at the beginning and/or end of the filter<br>";
+ if (classValue.indexOf("*", 1) != (classValue.length - 1)) {
+ throwableClassHasError = true;
+ errorsHtml += "ERROR: Invalid Exception class filter: wildcards can only be used at the beginning and/or end of the filter<br>";
} else if (document.getElementById("event_throwable_method").value != "") {
- // Wildcard not allowed at the end of the string if a method filter is enabled
- resultIsGreen = false;
- setErrorStyle(throwableClassElement);
- errorsHtml += "ERROR: Exception class filter must not end with a wildcard when a method filter is specified<br>";
- } else {
- // Wildcard looks ok
- unsetErrorStyle(throwableClassElement);
+ throwableClassHasError = true
+ errorsHtml += "ERROR: Invalid Exception class filter: must not end with a wildcard when a method filter is specified<br>";
}
+ }
+
+ if (classValue.indexOf(",") != -1) {
+ throwableClassHasError = true;
+ errorsHtml += "ERROR: Invalid Exception class filter: must not contain a comma.<br>";
+ }
+
+ if (throwableClassHasError) {
+ resultIsGreen = false;
+ setErrorStyle(throwableClassElement);
} else {
- // No wildcard, or a single wildcard at the beginning of the string
- // Note: A filter containing just a wildcard (i.e. "*") is also fine
unsetErrorStyle(throwableClassElement);
- }
+ }
}
- // Check validity of any wildcard in the throwable method string
+ // Check validity of the throwable method filter. Rules:
+ // 1. Can end with a wildcard character if no stack offset is specified
+ // 2. Cannot contain a wildcard in any other location
+ // 3. Cannot contain a comma
+ var throwableMethodHasError = false;
var throwableMethodElement = document.getElementById("event_throwable_method");
if (!throwableMethodElement.disabled) {
var methodValue = throwableMethodElement.value;
- if (methodValue.indexOf("*") != -1) {
- if (document.getElementById("event_throwable_offset").value != "0") {
- // No wildcard allowed if using stack offset
- resultIsGreen = false;
- setErrorStyle(throwableMethodElement);
- errorsHtml += "ERROR: Exception method filter must not contain a wildcard when using a stack offset.<br>";
- } else if (methodValue.indexOf("*") != (methodValue.length - 1)) {
- // If no stack offset, wildcard must be placed at the end
- resultIsGreen = false;
- setErrorStyle(throwableMethodElement);
- errorsHtml += "ERROR: Exception method filter wildcard can only be used at the end of the filter<br>";
- } else {
- // Wildcard looks ok
- unsetErrorStyle(throwableMethodElement);
- }
+
+ var wildcardIndex = methodValue.indexOf("*");
+ if (wildcardIndex != -1) {
+ if (wildcardIndex != (methodValue.length - 1)) {
+ throwableMethodHasError = true;
+ errorsHtml += "ERROR: Invalid Exception method filter: wildcard can only be used at the end of the filter<br>";
+ } else if (document.getElementById("event_throwable_offset").value != "0") {
+ throwableMethodHasError = true;
+ errorsHtml += "ERROR: Invalid Exception method filter: must not end with a wildcard when using a non-zero stack offset.<br>";
+ }
+ }
+
+ if (methodValue.indexOf(",") != -1) {
+ throwableMethodHasError = true;
+ errorsHtml += "ERROR: Invalid Exception method filter: must not contain a comma.<br>";
+ }
+
+ if (throwableMethodHasError) {
+ resultIsGreen = false;
+ setErrorStyle(throwableMethodElement);
} else {
- // No wildcard
unsetErrorStyle(throwableMethodElement);
}
}
+ // Check validity of the throwable message filter string
+ var throwableMessageElement = document.getElementById("event_throwable_msg_filter");
+ if (throwableMessageElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(throwableMessageElement);
+ errorsHtml += "ERROR: Invalid Exception message filter: must not contain a comma.<br>";
+ } else {
+ unsetErrorStyle(throwableMessageElement);
+ }
+
+ // Check validity of the class load/unload filter string
+ var classFilterElement = document.getElementById("event_class_filter");
+ if (classFilterElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(classFilterElement);
+ errorsHtml += "ERROR: Invalid class load/unload filter: must not contain a comma.<br>";
+ } else {
+ unsetErrorStyle(classFilterElement);
+ }
+
// Check that a priority has been specified if the dump priority option is selected
var priorityValueElement = document.getElementById("priority_value");
if (document.getElementById("priority").checked && priorityValueElement.value == "") {
@@ -866,6 +892,10 @@ function buildAndUpdateResult() {
resultIsGreen = false;
setErrorStyle(priorityValueElement);
errorsHtml += "ERROR: Dump file option is checked, but no file name has been specified<br>";
+ } else if (dumpFileElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(dumpFileElement);
+ errorsHtml += "ERROR: Invalid dump file name: must not contain a comma.<br>";
} else {
unsetErrorStyle(priorityValueElement);
}
@@ -1464,7 +1494,7 @@ ul {
<b><p id="result" style="font-size: 14pt; font-family:courier;">&nbsp;</p></b>
<hr>
<p>
- <input type="checkbox" id="wrap_in_quotes" name="wrap_in_quotes" value="wrap_in_quotes" onchange="processChange(this)">
+ <input type="checkbox" id="wrap_in_quotes" name="wrap_in_quotes" value="wrap_in_quotes" onchange="processChange(this)" checked>
<label for="wrap_in_quotes">Wrap in quotes (for use in a shell)</label>
</p>
<p>
diff --git a/tools/xtrace_option_builder.html b/tools/xtrace_option_builder.html
index 6033163..fdf8852 100644
--- a/tools/xtrace_option_builder.html
+++ b/tools/xtrace_option_builder.html
@@ -1356,17 +1356,21 @@ function fixTracepointIdCase(id) {
"Audio"
];
- // If the specified component matches an component in the table (case insensitive match), return the correct form
- var idArray = id.split(".");
- var component = idArray[0];
- var tracepointNumber = idArray[1];
- for (var i = 0; i < knownComponents.length; i++) {
- if (component.toLowerCase() == knownComponents[i].toLowerCase()) {
- return knownComponents[i] + "." + tracepointNumber;
+ // If the ID looks valid and the specified component matches an component in the table
+ // (case insensitive match), return the correct form
+ if (id.match(/^([a-zA-Z0-9])+\.\d+(-\d+)?$/) != null) {
+ var idArray = id.split(".");
+ var component = idArray[0];
+ var tracepointNumber = idArray[1];
+ for (var i = 0; i < knownComponents.length; i++) {
+ if (component.toLowerCase() == knownComponents[i].toLowerCase()) {
+ return knownComponents[i] + "." + tracepointNumber;
+ }
}
}
- // If we reach here the ID contains an unknown component, so just return it without making any changes
+ // If we reach here the tracepoint ID is either invalid or contains an unknown component,
+ // so just return it without making any changes
return id;
}
@@ -1513,7 +1517,13 @@ function buildAndUpdateResult() {
// TODO: This doesn't work properly on Linux if there is an '!' in a method/tpnid field
// Single quotes don't work on Windows...
if (document.getElementById("wrap_in_quotes").checked) {
- // Then wrap the entire result string in quotes
+ // Escape backslashes
+ resultString = resultString.replace(/\\/g, "\\\\");
+
+ // Escape quotes
+ resultString = resultString.replace(/"/g, "\\\"");
+
+ // Wrap the entire result string in quotes
resultString = "\"" + resultString + "\"";
}
@@ -1573,12 +1583,16 @@ function buildAndUpdateResult() {
for (var i = 0; i < methodCounter; i++) {
var methodSpecElement = document.getElementById("meth_text_" + i);
- // Check that each method option actually contains a method spec
+ // Check that each method option actually contains a valid-looking method spec
if (methodSpecElement != null) {
if (methodSpecElement.value == "") {
resultIsGreen = false;
setErrorStyle(methodSpecElement);
errorsHtml += "ERROR: Missing method specification in method trace<br>";
+ } else if (methodSpecElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(methodSpecElement);
+ errorsHtml += "ERROR: Invalid method specification: must not contain a comma: \"" + escapeHTML(methodSpecElement.value) + "\"<br>";
} else {
unsetErrorStyle(methodSpecElement);
}
@@ -1642,17 +1656,23 @@ function buildAndUpdateResult() {
setErrorStyle(methodSpecElement);
errorsHtml += "ERROR: Missing method specification in trigger<br>";
} else {
- // Method spec is present
- unsetErrorStyle(methodSpecElement);
+ // Check whether the method spec looks valid
+ if (methodSpecElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(methodSpecElement);
+ errorsHtml += "ERROR: Invalid method specification: must not contain a comma: \"" + escapeHTML(methodSpecElement.value) + "\"<br>";
+ } else {
+ unsetErrorStyle(methodSpecElement);
+ }
// Check that an entry or exit action is provided
var entryActionElement = getSelectedElement(document.getElementById("trig_meth_ent_" + i));
var exitActionElement = getSelectedElement(document.getElementById("trig_meth_ex_" + i));
if (entryActionElement.value == "none" && exitActionElement.value == "none") {
- resultIsGreen = false;
+ resultIsGreen = false;
setErrorStyle(entryActionElement);
setErrorStyle(exitActionElement);
- errorsHtml += "ERROR: No entry/exit action selected for method trigger: " + methodSpecElement.value + "<br>";
+ errorsHtml += "ERROR: No entry/exit action selected for method trigger: " + escapeHTML(methodSpecElement.value) + "<br>";
} else {
unsetErrorStyle(entryActionElement);
unsetErrorStyle(exitActionElement);
@@ -1748,8 +1768,18 @@ function buildAndUpdateResult() {
// Warning only - output file is not manadatory
warningsHtml += "WARNING: No output file specified for trace buffers (trace will still be visible in snap dumps)<br>";
} else if (containsReservedChars(fileTextElement.value)) {
- warningsHtml += "WARNING: Trace buffer output file contains a character that is disallowed on some platforms<br>";
+ warningsHtml += "WARNING: Trace buffer output file name contains a character that is disallowed on some platforms<br>";
}
+
+ // We have to do this separately (instead of in an else if) to ensure that the
+ // error style always gets unset after removing the comma
+ if (fileTextElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(fileTextElement);
+ errorsHtml += "ERROR: Invalid trace buffer output file name: must not contain a comma.<br>";
+ } else {
+ unsetErrorStyle(fileTextElement);
+ }
}
var exceptionFileTextElement = document.getElementById("file_text_exception");
if (!exceptionFileTextElement.disabled) {
@@ -1758,12 +1788,16 @@ function buildAndUpdateResult() {
resultIsGreen = false;
setErrorStyle(exceptionFileTextElement);
errorsHtml += "ERROR: No output file specified for Exception trace buffers<br>";
+ } else if (exceptionFileTextElement.value.indexOf(",") != -1) {
+ resultIsGreen = false;
+ setErrorStyle(fileTextElement);
+ errorsHtml += "ERROR: Invalid Exception trace buffer output file name: must not contain a comma.<br>";
} else {
unsetErrorStyle(exceptionFileTextElement);
}
if (containsReservedChars(exceptionFileTextElement.value)) {
- warningsHtml += "WARNING: Exception trace buffer output file contains a character that is disallowed on some platforms<br>";
+ warningsHtml += "WARNING: Exception trace buffer output file name contains a character that is disallowed on some platforms<br>";
}
} else {
unsetErrorStyle(exceptionFileTextElement);
@@ -2141,16 +2175,8 @@ function getOutputResultString() {
if (!fileElement.disabled) {
var fileString = fileElement.value;
if (fileString != "") {
- // Escape quotes in the filename
- // (I'm not sure what sort of monster would put quotes in the filename, but hey)
- fileString = fileString.replace(/"/g, "\\\"");
-
- // Wrap the filename in quotes if the entire option isn't going to be wrapped in quotes
- if (document.getElementById("wrap_in_quotes").checked) {
- regularOutputString += fileString + ",";
- } else {
- regularOutputString += "\"" + fileString + "\",";
- }
+ // File name
+ regularOutputString += fileString + ",";
// Max size and generations
var maxSize = document.getElementById("output_size").value;
@@ -2172,18 +2198,8 @@ function getOutputResultString() {
// This field is *mandatory* if the Exception destination is selected
fileElement = document.getElementById("file_text_exception");
if (!fileElement.disabled) {
- var fileString = fileElement.value;
-
- // Escape quotes in the filename
- // (I'm not sure what sort of monster would put quotes in the filename, but hey)
- fileString = fileString.replace(/"/g, "\\\"");
-
- // Wrap the filename in quotes if the entire option isn't going to be wrapped in quotes
- if (document.getElementById("wrap_in_quotes").checked) {
- exceptionOutputString += fileString + ",";
- } else {
- exceptionOutputString += "\"" + fileString + "\",";
- }
+ // File name
+ exceptionOutputString += fileElement.value + ",";
// Maximum size
var maxSize = document.getElementById("output_size_exception").value;

Back to the top