relays: refuse a WARDEN_GPIO_ROOT too long for PATH_MAX #11

Merged
noah merged 1 commits from fix-10-relay-path-bound into flare-edge-next 2026-10-02 12:14:30 -06:00
Owner

Fixes #10.

The relay driver built every sysfs path in fixed 80/96-byte stack buffers with unchecked snprintf. A WARDEN_GPIO_ROOT longer than about 70 bytes was cut short, so both relays silently read as unavailable. Production (/sys/class/gpio) is unaffected; the simulator and host-test seam are.

Change

  • relay_paths() formats all four paths of an operation (gpioN, export, gpioN/direction, gpioN/value) up front into PATH_MAX buffers and checks every snprintf return.
  • A root whose longest path does not fit is refused with a stderr line (relays: WARDEN_GPIO_ROOT is too long ...); available/get return false and set is a no-op. Nothing is truncated.
  • The export argument comes from a constant table, so no other runtime formatting remains.
  • Bound documented in relays.h; coverage counts updated in drivers/README.md and docs.

Tests

make -C drivers/relays/test check: 58 checks, 0 failures, 100% MC/DC (50/50 conditions, 65/65 lines).

New cases: a 200-byte root through the fake io (the full untruncated path reaches the backend), a root exactly at the PATH_MAX bound (accepted), one byte over (refused and logged on available, get and set, io never touched), a root over PATH_MAX, and a real scratch tree under a root over 200 bytes (both relays available and switchable).

With relays.c reverted to flare-edge-next, the same harness reports 17 failures.

Consumed by flare-edge via the submodule bump in blueflare/flare-edge#318.

Generated with Claude Code

https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg

Fixes #10. The relay driver built every sysfs path in fixed 80/96-byte stack buffers with unchecked `snprintf`. A `WARDEN_GPIO_ROOT` longer than about 70 bytes was cut short, so both relays silently read as unavailable. Production (`/sys/class/gpio`) is unaffected; the simulator and host-test seam are. ## Change - `relay_paths()` formats all four paths of an operation (`gpioN`, `export`, `gpioN/direction`, `gpioN/value`) up front into PATH_MAX buffers and checks every `snprintf` return. - A root whose longest path does not fit is refused with a stderr line (`relays: WARDEN_GPIO_ROOT is too long ...`); `available`/`get` return false and `set` is a no-op. Nothing is truncated. - The export argument comes from a constant table, so no other runtime formatting remains. - Bound documented in `relays.h`; coverage counts updated in `drivers/README.md` and docs. ## Tests `make -C drivers/relays/test check`: 58 checks, 0 failures, 100% MC/DC (50/50 conditions, 65/65 lines). New cases: a 200-byte root through the fake io (the full untruncated path reaches the backend), a root exactly at the PATH_MAX bound (accepted), one byte over (refused and logged on available, get and set, io never touched), a root over PATH_MAX, and a real scratch tree under a root over 200 bytes (both relays available and switchable). With `relays.c` reverted to `flare-edge-next`, the same harness reports 17 failures. Consumed by flare-edge via the submodule bump in blueflare/flare-edge#318. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
noah added 1 commit 2026-10-02 11:03:35 -06:00
relays: refuse a WARDEN_GPIO_ROOT too long for PATH_MAX
ci / test (push) Successful in 16s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / bench (push) Successful in 11s
ci / patches-apply (push) Successful in 22s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 37s
ci / badges (push) Skipped
ci / qemu-tools (pull_request) Successful in 45s
ci / qemu-tools (push) Successful in 49s
ci / test (pull_request) Successful in 17s
ci / mcdc (pull_request) Successful in 19s
ci / bench (pull_request) Successful in 8s
ci / mcdc (push) Successful in 23s
ci / patches-apply (pull_request) Successful in 22s
ci / quality (pull_request) Successful in 34s
ci / badges (pull_request) Skipped
b18ed3888b
Sysfs paths were built in fixed 80/96-byte stack buffers with unchecked
snprintf, so a root longer than about 70 bytes was truncated and both relays
silently read as unavailable.

Each operation now formats all of its paths up front into PATH_MAX buffers
and checks every snprintf return. A root whose longest path does not fit is
refused with a stderr line and the call reports unavailable, off or no-op;
nothing is ever truncated. The export argument comes from a constant table
instead of runtime formatting.

Regression tests: a 200-byte root through the fake io (full path reaches
the backend), the exact PATH_MAX boundary, one byte over (refused and logged
on available, get and set, io untouched), and a real scratch tree under a
root over 200 bytes. MC/DC stays at 100% (50/50 conditions).

Fixes #10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
noah merged commit 45569611da into flare-edge-next 2026-10-02 12:14:30 -06:00
noah deleted branch fix-10-relay-path-bound 2026-10-02 12:14:30 -06:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: blueflare/bfe-core1106-sdk#11