From e02db37a87aeca46e4b498514139222dc70c179e Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Fri, 8 Apr 2016 17:23:41 +0100 Subject: [PATCH] Check that transport ID isn't empty. --- .../keyagreement/PayloadParserImpl.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/briar-core/src/org/briarproject/keyagreement/PayloadParserImpl.java b/briar-core/src/org/briarproject/keyagreement/PayloadParserImpl.java index d13f9ff732..4be5b2f9fc 100644 --- a/briar-core/src/org/briarproject/keyagreement/PayloadParserImpl.java +++ b/briar-core/src/org/briarproject/keyagreement/PayloadParserImpl.java @@ -35,18 +35,18 @@ class PayloadParserImpl implements PayloadParser { BdfReader r = bdfReaderFactory.createReader(in); r.readListStart(); // Payload start int proto = (int) r.readLong(); - if (proto != PROTOCOL_VERSION) - throw new FormatException(); + if (proto != PROTOCOL_VERSION) throw new FormatException(); byte[] commitment = r.readRaw(COMMIT_LENGTH); - if (commitment.length != COMMIT_LENGTH) - throw new FormatException(); - List<TransportDescriptor> descriptors = new ArrayList<TransportDescriptor>(); + if (commitment.length != COMMIT_LENGTH) throw new FormatException(); + List<TransportDescriptor> descriptors = + new ArrayList<TransportDescriptor>(); r.readListStart(); // Descriptors start - while (r.hasList()) { + while (!r.hasListEnd()) { r.readListStart(); while (!r.hasListEnd()) { - TransportId id = - new TransportId(r.readString(MAX_PROPERTY_LENGTH)); + String idString = r.readString(MAX_PROPERTY_LENGTH); + if (idString.isEmpty()) throw new FormatException(); + TransportId id = new TransportId(idString); TransportProperties p = new TransportProperties(); r.readDictionaryStart(); while (!r.hasDictionaryEnd()) { @@ -61,8 +61,7 @@ class PayloadParserImpl implements PayloadParser { } r.readListEnd(); // Descriptors end r.readListEnd(); // Payload end - if (!r.eof()) - throw new FormatException(); + if (!r.eof()) throw new FormatException(); return new Payload(commitment, descriptors); } } -- GitLab