Skip to content

Commit 55de256

Browse files
hyperpolymathclaude
andcommitted
fix(security): panic-attack P10 — classify FFI ptrCast in cartridge_shim
ffi/cartridge_shim.zig toolIs(): add explicit safety doc explaining why @ptrCast([*c]const u8 → [*:0]const u8) is safe at this C-ABI boundary — ADR-0006 requires NUL-terminated tool_name; not a banned unsafe cast but a legitimate FFI pattern at the cartridge ABI seam. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c95a347 commit 55de256

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cartridges/echidna-llm-mcp/ffi/cartridge_shim.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ pub fn invokeArgsNull(
5858
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
5959
/// literal. Caller must have already verified `tool_name` is non-null
6060
/// (usually via `invokeArgsNull`).
61+
///
62+
/// Safety: @ptrCast from [*c]const u8 to [*:0]const u8 is safe at this
63+
/// C-ABI boundary — the BoJ cartridge ABI (ADR-0006) requires all
64+
/// tool_name arguments to be NUL-terminated C strings. Non-NUL-terminated
65+
/// inputs violate the calling convention and are the caller's fault.
6166
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
62-
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
67+
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name))); // FFI boundary: NUL-termination guaranteed by ADR-0006
6368
return std.mem.eql(u8, s, expected);
6469
}
6570

0 commit comments

Comments
 (0)