Keep scanner reinit state instance-local
What changed, and why it matters
This tiny code change moves a 'needs reinit' flag from being shared across all QR scanner objects to being kept inside each individual scanner object. In the real device code the flag is removed from the base class; in the simulator it is added as an instance variable. The change is a bug-fix style cleanup that prevents scanner state from leaking between different scanner instances. There is no direct evidence in the commit of a security vulnerability, but shared mutable state can in principle cause race-condition or state-confusion bugs.
No immediate action required. Treat as routine defensive hardening. If auditing, verify that all `QRScanner` subclasses initialize `needs_reinit` per-instance and that no code path relies on the removed class-level default.
Security signals we found
Shared mutable class-level state removed
State variable made instance-local
Potential race-condition / state-confusion class eliminated
Evidence from the diff
The patch removes the class-level attribute needs_reinit = False from QRScanner in shared/scanner.py and adds self.needs_reinit = False to the simulator’s SimulatedQRScanner.__init__ in unix/variant/sim_scanner.py. This makes the reinitialization state instance-local rather than class-global. The real hardware subclass presumably already sets the attribute per-instance (not shown in the diff). The change is defensive and reduces the risk of state cross-talk between multiple scanner instances or between the simulator and real code paths.
Changed components
shared/scanner.pyunix/variant/sim_scanner.pyInspect captured patch +1 / −2
diff --git a/shared/scanner.py b/shared/scanner.py
index af048a7..df305cb 100644
--- a/shared/scanner.py
+++ b/shared/scanner.py
@@ -61,8 +61,6 @@ RX_BUF_SIZE = const(4350) # big enough for full v40 decoded
# command sleep is the known low-power state.
class QRScanner:
- needs_reinit = False
-
def __init__(self):
self.busy_scanning = False
diff --git a/unix/variant/sim_scanner.py b/unix/variant/sim_scanner.py
index a3cd5fc..43ac698 100644
--- a/unix/variant/sim_scanner.py
+++ b/unix/variant/sim_scanner.py
@@ -17,6 +17,7 @@ class SimulatedQRScanner(QRScanner):
self.busy_scanning = False
self.setup_done = True
self.version = 'V2.3.420'
+ self.needs_reinit = False
self.lock = asyncio.Lock()
# returns a Q we append to as results come in
self._q = Queue()
Why this scored 26/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.