fix: can crash if scanner not initialized
What changed, and why it matters
This is a small bug-fix in the COLDCARD hardware wallet's battery monitoring code. It prevents a crash that could occur if a background battery check runs before the QR-code scanner module has finished starting up. The change makes the code safely skip the check when the scanner isn't ready yet, rather than trying to read a value that doesn't exist and crashing.
Treat as a routine stability fix. Review whether other background tasks access SCAN without a null guard, and consider initializing SCAN earlier or making it always non-None to eliminate similar races. No urgent security response is indicated by the diff alone.
Security signals we found
Null-pointer-like guard added to prevent crash in background task
Background task (batt_idle_logout) could terminate unexpectedly without the fix
Crash in battery/logout logic could affect device availability or user experience
No explicit security claim made by vendor in commit message
Evidence from the diff
In shared/battery.py, the batt_idle_logout() coroutine polls every 20 seconds and checks SCAN.busy_scanning to avoid logging out while the QR scanner is active. If SCAN is None because the scanner module has not yet been initialized, the bare attribute access raises an AttributeError (or similar) and crashes the task. The patch guards the access with ‘if SCAN and SCAN.busy_scanning:’, short-circuiting when SCAN is None. This is a defensive null-check, not a logic change.
Changed components
shared/battery.pybatt_idle_logout coroutineQR scanner integration (SCAN object)Inspect captured patch +1 / −1
diff --git a/shared/battery.py b/shared/battery.py
index be96290..6faeed7 100644
--- a/shared/battery.py
+++ b/shared/battery.py
@@ -144,7 +144,7 @@ async def batt_idle_logout():
while True:
await sleep_ms(20000) # 20 seconds
- if SCAN.busy_scanning:
+ if SCAN and SCAN.busy_scanning:
continue
if get_batt_level() is None:
Why this scored 33/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.