mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 15:49:53 +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 {
|
try {
|
||||||
// Get the current connection counter
|
// Get the current connection counter
|
||||||
String sql = "SELECT outgoing FROM secrets"
|
String sql = "SELECT outgoing FROM secrets"
|
||||||
+ " WHERE contactId = ? AND transportId = ? AND period + ?";
|
+ " WHERE contactId = ? AND transportId = ? AND period = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setBytes(2, t.getBytes());
|
ps.setBytes(2, t.getBytes());
|
||||||
ps.setLong(3, period);
|
ps.setLong(3, period);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if(!rs.next()) throw new DbStateException();
|
if(!rs.next()) {
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return -1L;
|
||||||
|
}
|
||||||
long connection = rs.getLong(1);
|
long connection = rs.getLong(1);
|
||||||
if(rs.next()) throw new DbStateException();
|
if(rs.next()) throw new DbStateException();
|
||||||
rs.close();
|
rs.close();
|
||||||
@@ -2055,7 +2059,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.setBytes(2, t.getBytes());
|
ps.setBytes(2, t.getBytes());
|
||||||
ps.setLong(3, period);
|
ps.setLong(3, period);
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected > 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
return connection;
|
return connection;
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user