Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2014-08-13 19:52:27 +0000
committerMatthew Khouzam2014-08-18 17:50:14 +0000
commitbd13cffb445f083d1e065c96f355887e547cc410 (patch)
treede58f79e7ec9b26519dd6da025e5e8330e3ac3ac
parentf386a1d053fc74851183755418d96661e2e90b04 (diff)
downloadorg.eclipse.linuxtools-bd13cffb445f083d1e065c96f355887e547cc410.tar.gz
org.eclipse.linuxtools-bd13cffb445f083d1e065c96f355887e547cc410.tar.xz
org.eclipse.linuxtools-bd13cffb445f083d1e065c96f355887e547cc410.zip
ctf: make id conversions in event headers safer
Change-Id: I4fcfb986f5e1ff0010fcd4b6692075c3dbfd175e Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-on: https://git.eclipse.org/r/31569 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java5
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java17
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java7
3 files changed, 18 insertions, 11 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java
index 4f2094c87e..07fa8d804d 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java
@@ -149,7 +149,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
if (!(fStreamEventHeaderDecl instanceof StructDeclaration)) {
throw new IllegalStateException("Definition is not a struct definition, this is a deprecated method that doesn't work so well, stop using it."); //$NON-NLS-1$
}
- return ((StructDeclaration)fStreamEventHeaderDecl).createDefinition(this, LexicalScope.STREAM_EVENT_HEADER, input);
+ return ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(this, LexicalScope.STREAM_EVENT_HEADER, input);
}
/**
@@ -499,7 +499,8 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
* Get stream event header
*
* @return the stream event header
- * @deprecated use {@link CTFStreamInputPacketReader#getStreamEventHeaderDefinition()}
+ * @deprecated use
+ * {@link CTFStreamInputPacketReader#getStreamEventHeaderDefinition()}
*/
@Deprecated
public StructDefinition getCurrentStreamEventHeader() {
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java
index 7e734ee553..58cbc2dcbe 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java
@@ -109,10 +109,13 @@ public class EventHeaderCompactDeclaration extends Declaration implements IEvent
}
// needed since we read 5 bits
input.position(input.position() + 3);
- int id = (int) input.get(ID_SIZE, false);
+ long id = input.get(ID_SIZE, false);
+ if (id > Integer.MAX_VALUE) {
+ throw new CTFReaderException("ID " + id + " larger than " + Integer.MAX_VALUE + " is currently unsupported by the parser"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
long timestampLong = input.get(FULL_TS, false);
input.setByteOrder(bo);
- return new EventHeaderDefinition(this, id, timestampLong, FULL_TS);
+ return new EventHeaderDefinition(this, (int) id, timestampLong, FULL_TS);
}
@@ -152,11 +155,11 @@ public class EventHeaderCompactDeclaration extends Declaration implements IEvent
if (!vDec.hasField(COMPACT) || !vDec.hasField(EXTENDED)) {
return false;
}
- if( vDec.getFields().size()!= VARIANT_SIZE) {
+ if (vDec.getFields().size() != VARIANT_SIZE) {
return false;
}
iDeclaration = vDec.getFields().get(COMPACT);
- if( !(iDeclaration instanceof StructDeclaration)) {
+ if (!(iDeclaration instanceof StructDeclaration)) {
return false;
}
StructDeclaration compactDec = (StructDeclaration) iDeclaration;
@@ -167,7 +170,7 @@ public class EventHeaderCompactDeclaration extends Declaration implements IEvent
return false;
}
iDeclaration = compactDec.getFields().get(TIMESTAMP);
- if(!(iDeclaration instanceof IntegerDeclaration)) {
+ if (!(iDeclaration instanceof IntegerDeclaration)) {
return false;
}
IntegerDeclaration tsDec = (IntegerDeclaration) iDeclaration;
@@ -175,7 +178,7 @@ public class EventHeaderCompactDeclaration extends Declaration implements IEvent
return false;
}
iDeclaration = vDec.getFields().get(EXTENDED);
- if( !(iDeclaration instanceof StructDeclaration)) {
+ if (!(iDeclaration instanceof StructDeclaration)) {
return false;
}
StructDeclaration extendedDec = (StructDeclaration) iDeclaration;
@@ -186,7 +189,7 @@ public class EventHeaderCompactDeclaration extends Declaration implements IEvent
return false;
}
iDeclaration = extendedDec.getFields().get(TIMESTAMP);
- if(!(iDeclaration instanceof IntegerDeclaration)) {
+ if (!(iDeclaration instanceof IntegerDeclaration)) {
return false;
}
tsDec = (IntegerDeclaration) iDeclaration;
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java
index a61debd62d..7b0acf0ce7 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java
@@ -102,14 +102,17 @@ public class EventHeaderLargeDeclaration extends Declaration implements IEventHe
ByteOrder bo = input.getByteOrder();
input.setByteOrder(fByteOrder);
int first = (int) input.get(COMPACT_ID, false);
- int second = (int) input.get(COMPACT_TS, false);
+ long second = input.get(COMPACT_TS, false);
if (first != EXTENDED_VALUE) {
input.setByteOrder(bo);
return new EventHeaderDefinition(this, first, second, COMPACT_TS);
}
long timestampLong = input.get(FULL_TS, false);
input.setByteOrder(bo);
- return new EventHeaderDefinition(this, second, timestampLong, FULL_TS);
+ if (second > Integer.MAX_VALUE) {
+ throw new CTFReaderException("ID " + second + " larger than " + Integer.MAX_VALUE + " is currently unsupported by the parser"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+ return new EventHeaderDefinition(this, (int) second, timestampLong, FULL_TS);
}
@Override

Back to the top