From fbe1c799dd948421e841a60619d7d67f37ea0805 Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Fri, 4 Apr 2014 02:23:09 +0100
Subject: [PATCH] Added canary code to catch bugs #55 and #65.

---
 briar-core/src/org/briarproject/db/JdbcDatabase.java | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java
index 72c35f358c..3178847e7d 100644
--- a/briar-core/src/org/briarproject/db/JdbcDatabase.java
+++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java
@@ -1205,8 +1205,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<GroupStatus> groups = new ArrayList<GroupStatus>();
+			Set<GroupId> ids = new HashSet<GroupId>();
 			while(rs.next()) {
 				GroupId id = new GroupId(rs.getBytes(1));
+				if(!ids.add(id)) throw new DbStateException();
 				String name = rs.getString(2);
 				byte[] salt = rs.getBytes(3);
 				Group group = new Group(id, name, salt);
@@ -1226,6 +1228,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs = ps.executeQuery();
 			while(rs.next()) {
 				GroupId id = new GroupId(rs.getBytes(1));
+				if(!ids.add(id)) throw new DbStateException();
 				String name = rs.getString(2);
 				byte[] salt = rs.getBytes(3);
 				Group group = new Group(id, name, salt);
@@ -2246,10 +2249,12 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(2, now);
 			rs = ps.executeQuery();
 			List<Group> groups = new ArrayList<Group>();
+			Set<GroupId> ids = new HashSet<GroupId>();
 			long version = 0;
 			int txCount = 0;
 			while(rs.next()) {
 				GroupId id = new GroupId(rs.getBytes(1));
+				if(!ids.add(id)) throw new DbStateException();
 				String name = rs.getString(2);
 				byte[] salt = rs.getBytes(3);
 				groups.add(new Group(id, name, salt));
-- 
GitLab