fix(safety): harden dual-core atomics, UDP peer filtering, TOCTOU, and CRC-8 UART frames

This commit is contained in:
bleack committed 2026-11-23 22:34:13 +01:00
1 parent 426ab7c7d6
commit c0bad51d3b
9 files changed
+232 -72

No files matched your search

+18 -2
View File
@@ -15,6 +15,7 @@ import time
from typing import Optional
BAUD_RATE = termios.B460800
BIND_IP = os.environ.get("STEAMFRAME_BIND_IP", "192.168.1.1")
CASQUE_IP = os.environ.get("STEAMFRAME_CASQUE_IP", "192.168.1.10")
UDP_PORT = int(os.environ.get("STEAMFRAME_G29_PORT", "14552"))
SERIAL_CANDIDATES = (
@@ -58,9 +59,22 @@ def find_serial_device() -> Optional[str]:
def main() -> None:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0", UDP_PORT))
try:
sock.bind((BIND_IP, UDP_PORT))
bound_ip = BIND_IP
except OSError as exc:
print(
f"[radxa_g29_relay] Bind {BIND_IP}:{UDP_PORT} impossible ({exc}), fallback 0.0.0.0",
file=sys.stderr,
flush=True,
)
sock.bind(("0.0.0.0", UDP_PORT))
bound_ip = "0.0.0.0"
sock.setblocking(False)
print(f"[radxa_g29_relay] UDP :0.0.0.0:{UDP_PORT} <-> {CASQUE_IP}:{UDP_PORT}", flush=True)
print(
f"[radxa_g29_relay] UDP {bound_ip}:{UDP_PORT} <-> {CASQUE_IP}:{UDP_PORT} (filtre IP actif)",
flush=True,
)
serial_fd: Optional[int] = None
serial_buf = bytearray()
@@ -97,6 +111,8 @@ def main() -> None:
if sock.fileno() in readable:
try:
data, addr = sock.recvfrom(512)
if addr[0] not in (CASQUE_IP, "127.0.0.1"):
continue
last_casque_addr = (addr[0], UDP_PORT)
if data:
os.write(serial_fd, data)