Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2018-03-17 21:53:15 -0400
committerMatthew Khouzam2018-04-11 14:17:04 -0400
commit10a823dd2e5875bdf2365e814b9b3e91f44d3245 (patch)
tree43f8b34e66d204d1d8045312a24dddb4ad65a29e
parentc17df49e0038e67180585dd721a73fde16d48c7c (diff)
downloadorg.eclipse.tracecompass.incubator-10a823dd2e5875bdf2365e814b9b3e91f44d3245.tar.gz
org.eclipse.tracecompass.incubator-10a823dd2e5875bdf2365e814b9b3e91f44d3245.tar.xz
org.eclipse.tracecompass.incubator-10a823dd2e5875bdf2365e814b9b3e91f44d3245.zip
traceevent: add safeguard against reading an improper termination
(char)-1 returns 65535, this patch keeps the reading as an integer as long as possible. Change-Id: I5f617959e3c3c1e33508c15b0805745d551f1e85 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-on: https://git.eclipse.org/r/119624 Tested-by: CI Bot Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
-rw-r--r--tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java18
1 files changed, 9 insertions, 9 deletions
diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java
index 0e2fb453..9c079967 100644
--- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java
+++ b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java
@@ -151,7 +151,7 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
goToCorrectStart(rafile);
int lineCount = 0;
int matches = 0;
- String line = readNextEventString(() -> (char) rafile.read());
+ String line = readNextEventString(() -> rafile.read());
while ((line != null) && (lineCount++ < MAX_LINES)) {
try {
TraceEventField field = TraceEventField.parseJson(line);
@@ -163,7 +163,7 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
}
confidence = MAX_CONFIDENCE * matches / lineCount;
- line = readNextEventString(() -> (char) rafile.read());
+ line = readNextEventString(() -> rafile.read());
}
if (matches == 0) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Most assuredly NOT a traceevent trace"); //$NON-NLS-1$
@@ -289,7 +289,7 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
if (!locationInfo.equals(fFileInput.getFilePointer())) {
fFileInput.seek(locationInfo);
}
- String nextJson = readNextEventString(() -> (char) fFileInput.read());
+ String nextJson = readNextEventString(() -> fFileInput.read());
while (nextJson != null) {
TraceEventField field = TraceEventField.parseJson(nextJson);
if (field == null) {
@@ -299,7 +299,7 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
return new TraceEventEvent(this, context.getRank(), field);
}
parseMetadata(field);
- nextJson = readNextEventString(() -> (char) fFileInput.read());
+ nextJson = readNextEventString(() -> fFileInput.read());
}
} catch (IOException e) {
Activator.getInstance().logError("Error parsing event", e); //$NON-NLS-1$
@@ -395,7 +395,7 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
* @throws IOException
* out of chars to read
*/
- char read() throws IOException;
+ int read() throws IOException;
}
/**
@@ -412,8 +412,8 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
int scope = -1;
int arrScope = 0;
boolean inQuotes = false;
- char elem = parser.read();
- while (elem != (char) -1) {
+ int elem = parser.read();
+ while (elem != -1) {
if (elem == '"') {
inQuotes = !inQuotes;
} else {
@@ -433,13 +433,13 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab
if (scope > 0) {
scope--;
} else {
- sb.append(elem);
+ sb.append((char) elem);
return sb.toString();
}
}
}
if (scope >= 0) {
- sb.append(elem);
+ sb.append((char) elem);
}
elem = parser.read();
}

Back to the top