0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-15 01:03:50 +01:00

Fix exception when a cross-signed device is deleted (#6462)

(hopefully)

... and deobfuscate the relevant bit of code.
This commit is contained in:
Richard van der Hoff 2019-12-04 07:38:35 +00:00 committed by GitHub
parent 54dd5dc12b
commit 0120875462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

1
changelog.d/6462.bugfix Normal file
View file

@ -0,0 +1 @@
Fix bug which lead to exceptions being thrown in a loop when a cross-signed device is deleted.

View file

@ -145,13 +145,28 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
txn.execute(signature_sql, signature_query_params) txn.execute(signature_sql, signature_query_params)
rows = self.cursor_to_dict(txn) rows = self.cursor_to_dict(txn)
# add each cross-signing signature to the correct device in the result dict.
for row in rows: for row in rows:
signing_user_id = row["user_id"]
signing_key_id = row["key_id"]
target_user_id = row["target_user_id"] target_user_id = row["target_user_id"]
target_device_id = row["target_device_id"] target_device_id = row["target_device_id"]
if target_user_id in result and target_device_id in result[target_user_id]: signature = row["signature"]
result[target_user_id][target_device_id].setdefault(
"signatures", {} target_user_result = result.get(target_user_id)
).setdefault(row["user_id"], {})[row["key_id"]] = row["signature"] if not target_user_result:
continue
target_device_result = target_user_result.get(target_device_id)
if not target_device_result:
# note that target_device_result will be None for deleted devices.
continue
target_device_signatures = target_device_result.setdefault("signatures", {})
signing_user_signatures = target_device_signatures.setdefault(
signing_user_id, {}
)
signing_user_signatures[signing_key_id] = signature
log_kv(result) log_kv(result)
return result return result