feat(micromate): one opcode table and a send-side gate -- writes refused unless allowed, 0xA2 always
micromate/opcodes.py holds WRITE_SUBS and the cross-series collision 0xA2.
MicromateProtocol._send reads the SUB of the bytes about to go out
(framing.request_sub) and refuses any write SUB not in allowed_writes, and
0xA2 unconditionally. Docstrings now say the reads-only policy is enforced.
request_sub also refuses any frame not in canonical form
(stuff(unstuff(body)) == body): an interior unescaped 02/03/04, a 10 XX
outside {02,03,04,10}, or a trailing lone DLE. What the gate checks is then
exactly what the unit parses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
151ba1546f
commit
a3e4e85dfd
6 files changed
+178
-9
No files matched your search
@@ -182,6 +182,12 @@ def request_sub(frame: bytes) -> int:
|
||||
body = unstuff(frame[2:-1])
|
||||
if len(body) < 17 or body[0] != MM_CMD:
|
||||
raise ValueError(f"not a host->unit request frame: {bytes(frame[:8]).hex()}")
|
||||
# Canonical form only: what this check reads must be exactly what the unit
|
||||
# parses. An unescaped 02/03/04, a `10 XX` outside {02,03,04,10} or a
|
||||
# trailing lone DLE would be read one way here and another by the unit.
|
||||
if stuff(body) != frame[2:-1]:
|
||||
raise ValueError(
|
||||
f"not a canonical request frame (stuffing differs): {bytes(frame[:8]).hex()}")
|
||||
return body[2]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user