Skip to content

Commit 8cd06bb

Browse files
committed
fix: use write transaction in SpkiHashStore.cleanup()
query_map_vec() uses read-only connection, so it cannot be used to delete rows.
1 parent bb816ff commit 8cd06bb

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

src/net/tls/spki.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
use std::collections::BTreeMap;
88

9-
use anyhow::Context as _;
109
use anyhow::Result;
1110
use base64::Engine as _;
1211
use parking_lot::RwLock;
@@ -97,25 +96,28 @@ impl SpkiHashStore {
9796
pub async fn cleanup(&self, sql: &Sql) -> Result<()> {
9897
let now = time();
9998
let removed_hosts = sql
100-
.query_map_vec(
101-
"DELETE FROM tls_spki WHERE ? > timestamp + ? RETURNING host",
102-
(now, 30 * 24 * 60 * 60),
103-
|row| {
99+
.transaction(|transaction| {
100+
let mut stmt = transaction
101+
.prepare("DELETE FROM tls_spki WHERE ? > timestamp + ? RETURNING host")?;
102+
let mut res = Vec::new();
103+
for row in stmt.query_map((now, 30 * 24 * 60 * 60), |row| {
104104
let host: String = row.get(0)?;
105105
Ok(host)
106-
},
107-
)
108-
.await
109-
.context("DELETE FROM tls_spki")?;
106+
})? {
107+
res.push(row?);
108+
}
110109

111-
// Fix timestamps that happen to be in the future
112-
// if we had clock set incorrectly when the timestamp was stored.
113-
// Otherwise entry may take more than 30 days to expire.
114-
sql.execute(
115-
"UPDATE tls_spki SET timestamp = ?1 WHERE timestamp > ?1",
116-
(now,),
117-
)
118-
.await?;
110+
// Fix timestamps that happen to be in the future
111+
// if we had clock set incorrectly when the timestamp was stored.
112+
// Otherwise entry may take more than 30 days to expire.
113+
transaction.execute(
114+
"UPDATE tls_spki SET timestamp = ?1 WHERE timestamp > ?1",
115+
(now,),
116+
)?;
117+
118+
Ok(res)
119+
})
120+
.await?;
119121

120122
let mut lock = self.hash_store.write();
121123
for host in removed_hosts {

0 commit comments

Comments
 (0)