Skip to content

Commit 5d66931

Browse files
committed
fix: do not allow to set ConfiguredAddr to arbitrary values
1 parent d155273 commit 5d66931

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

deltachat-rpc-client/tests/test_multitransport.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_change_address(acfactory) -> None:
5757
"""Test Alice configuring a second transport and setting it as a primary one."""
5858
alice, bob = acfactory.get_online_accounts(2)
5959

60+
bob_addr = bob.get_config("configured_addr")
6061
bob.create_chat(alice)
6162

6263
alice_chat_bob = alice.create_chat(bob)
@@ -70,6 +71,10 @@ def test_change_address(acfactory) -> None:
7071
qr = acfactory.get_account_qr()
7172
alice.add_transport_from_qr(qr)
7273
new_alice_addr = alice.list_transports()[1]["addr"]
74+
with pytest.raises(JsonRpcError):
75+
# Cannot use the address that is not
76+
# configured for any transport.
77+
alice.set_config("configured_addr", bob_addr)
7378
alice.set_config("configured_addr", new_alice_addr)
7479
with pytest.raises(JsonRpcError):
7580
alice.delete_transport(new_alice_addr)

src/config.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,26 @@ impl Context {
809809
.await?;
810810
}
811811
}
812-
self.sql.set_raw_config(key.as_ref(), value).await?;
812+
self.sql
813+
.transaction(|transaction| {
814+
if transaction.query_row(
815+
"SELECT COUNT(*) FROM transports WHERE addr=?",
816+
(value,),
817+
|row| {
818+
let res: i64 = row.get(0)?;
819+
Ok(res)
820+
},
821+
)? == 0
822+
{
823+
bail!("Address does not belong to any transport.");
824+
}
825+
transaction.execute(
826+
"UPDATE config SET value=? WHERE keyname='configured_addr'",
827+
(value,),
828+
)?;
829+
Ok(())
830+
})
831+
.await?;
813832
}
814833
_ => {
815834
self.sql.set_raw_config(key.as_ref(), value).await?;

0 commit comments

Comments
 (0)