mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Fixed a SQL typo and a race condition.
The typo caused the select statement to be under-selective; the race condition could have occurred if a contact transport was removed while an outgoing connection was being created.
This commit is contained in:
@@ -2036,13 +2036,17 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
try {
|
||||
// Get the current connection counter
|
||||
String sql = "SELECT outgoing FROM secrets"
|
||||
+ " WHERE contactId = ? AND transportId = ? AND period + ?";
|
||||
+ " WHERE contactId = ? AND transportId = ? AND period = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setBytes(2, t.getBytes());
|
||||
ps.setLong(3, period);
|
||||
rs = ps.executeQuery();
|
||||
if(!rs.next()) throw new DbStateException();
|
||||
if(!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
return -1L;
|
||||
}
|
||||
long connection = rs.getLong(1);
|
||||
if(rs.next()) throw new DbStateException();
|
||||
rs.close();
|
||||
@@ -2055,7 +2059,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setBytes(2, t.getBytes());
|
||||
ps.setLong(3, period);
|
||||
int affected = ps.executeUpdate();
|
||||
if(affected > 1) throw new DbStateException();
|
||||
if(affected != 1) throw new DbStateException();
|
||||
ps.close();
|
||||
return connection;
|
||||
} catch(SQLException e) {
|
||||
|
||||
Reference in New Issue
Block a user