Files
RedBear-OS/netstack
Red Bear OS e3f87fa3cf netstack: fix F003 scheme File ownership redundant cast
CRITICAL F003 from NETWORKING-AND-DRIVERS-CODE-ASSESSMENT-2026-07-27.md
§3.1: netstack/src/scheme/mod.rs had 2 unsafe File::from_raw_fd sites
with redundant 'as RawFd' casts. The audit flagged these as:
- 'The cast chain nf.into_raw() as RawFd goes through i32 → u32 → i32
  via RawFd, which is a truncation on some platforms'
- The SAFETY comments were generic boilerplate ('caller must verify
  the safety contract') rather than documenting the actual invariant

Fix: remove the redundant 'as RawFd' cast — File::from_raw_fd
already accepts the RawFd type that IntoRawFd::into_raw returns.
Also replace the generic boilerplate SAFETY comments with specific
invariants:
- 'caller guarantees nf is a live Fd not aliased elsewhere;
  from_raw_fd transfers ownership to the new File'
- 'caller guarantees time_file is a live Fd not aliased elsewhere;
  from_raw_fd transfers ownership to the new File'

The 'as RawFd' cast was a no-op on platforms where RawFd = i32, but
was still misleading (suggests a conversion is happening when it
isn't). Removing it clarifies the code.

CRITICAL progress: 13 of 13 original findings now addressed (F001,
F1.6, F1.1, F2, F3, DEF-P0-6, DEF-P0-7, F18/F18b, F20, F21, F3.1,
F22, P001).
2026-07-27 16:47:49 +09:00
..