Skip to content
Snippets Groups Projects
Commit 79166e9b authored by akwizgran's avatar akwizgran
Browse files

Reject subscription updates with duplicate entries. Bug #65.

parent dbfb309f
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,13 @@ import static org.briarproject.api.messaging.Types.SUBSCRIPTION_UPDATE;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.briarproject.api.FormatException;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.SubscriptionUpdate;
import org.briarproject.api.serial.Consumer;
import org.briarproject.api.serial.CountingConsumer;
......@@ -31,11 +34,15 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
r.addConsumer(counting);
// Read the start of the struct
r.readStructStart(SUBSCRIPTION_UPDATE);
// Read the subscriptions
// Read the subscriptions, rejecting duplicates
List<Group> groups = new ArrayList<Group>();
Set<GroupId> ids = new HashSet<GroupId>();
r.readListStart();
for(int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++)
groups.add(groupReader.readStruct(r));
for(int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) {
Group g = groupReader.readStruct(r);
if(!ids.add(g.getId())) throw new FormatException(); // Duplicate
groups.add(g);
}
r.readListEnd();
// Read the version number
long version = r.readInteger();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment