diff options
author | Patrick Tasse | 2014-06-02 21:27:59 +0000 |
---|---|---|
committer | Patrick Tasse | 2014-06-04 17:16:37 +0000 |
commit | c74f34d88b4776a5dde4937874afa4e3888432b2 (patch) | |
tree | 937d13265fce7755681f41478ad8bdccdb581368 | |
parent | 098b4b38094e618dde5c448115973a79b0c93d78 (diff) | |
download | org.eclipse.linuxtools-c74f34d88b4776a5dde4937874afa4e3888432b2.tar.gz org.eclipse.linuxtools-c74f34d88b4776a5dde4937874afa4e3888432b2.tar.xz org.eclipse.linuxtools-c74f34d88b4776a5dde4937874afa4e3888432b2.zip |
tmf: Bug 436376: CustomXML Trace Parser Undefined behaviour on closely
The Custom XML parser now properly handles element names which are a
truncation of another element's name.
Change-Id: I5bbf7d4832976fc75d8e60a9ebc0e09d1463bd51
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/27771
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
(cherry picked from commit 33937d3c8a9f55f7f1505a6617cf978536a933ee)
Reviewed-on: https://git.eclipse.org/r/27853
-rw-r--r-- | lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTrace.java | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTrace.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTrace.java index e300a79e89..c6a333de18 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTrace.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTrace.java @@ -148,11 +148,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer } else if (location.getLocationInfo() instanceof Long) { fFile.seek((Long) location.getLocationInfo()); } - final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$ long rawPos = fFile.getFilePointer(); String line = fFile.getNextLine(); while (line != null) { - final int idx = line.indexOf(recordElementStart); + final int idx = indexOfElement(fRecordInputElement.elementName, line, 0); if (idx != -1) { context.setLocation(new TmfLongLocation(rawPos + idx)); return context; @@ -256,12 +255,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer event = extractEvent(element, fRecordInputElement); ((StringBuffer) event.getContent().getValue()).append(elementBuffer); - - final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$ long rawPos = fFile.getFilePointer(); String line = fFile.getNextLine(); while (line != null) { - final int idx = line.indexOf(recordElementStart); + final int idx = indexOfElement(fRecordInputElement.elementName, line, 0); if (idx != -1) { context.setLocation(new TmfLongLocation(rawPos + idx)); return event; @@ -319,6 +316,23 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer return null; } + private static int indexOfElement(String elementName, String line, int fromIndex) { + final String recordElementStart = '<' + elementName; + int index = line.indexOf(recordElementStart, fromIndex); + if (index == -1) { + return index; + } + int nextCharIndex = index + recordElementStart.length(); + if (nextCharIndex < line.length()) { + char c = line.charAt(nextCharIndex); + // Check that the match is not just a substring of another element + if (Character.isLetterOrDigit(c)) { + return indexOfElement(elementName, line, nextCharIndex); + } + } + return index; + } + private void readElement(final StringBuffer buffer, final RandomAccessFile raFile) { try { int numRead = 0; @@ -521,11 +535,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer } try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$ int lineCount = 0; - final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$ long rawPos = 0; String line = rafile.getNextLine(); while ((line != null) && (lineCount++ < MAX_LINES)) { - final int idx = line.indexOf(recordElementStart); + final int idx = indexOfElement(fRecordInputElement.elementName, line, 0); if (idx != -1) { rafile.seek(rawPos + idx + 1); // +1 is for the < final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$ |