Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions cartridges/academic-workflow-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/aerie-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/affinescript-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/agent-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/airtable-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/arango-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/aws-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
26 changes: 16 additions & 10 deletions cartridges/bofig-mcp/ffi/cartridge_shim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ pub fn invokeArgsNull(
/// Compare a C-NUL-terminated tool-name pointer against a Zig string
/// literal. Caller must have already verified `tool_name` is non-null
/// (usually via `invokeArgsNull`).
///
/// Implementation note (CWE-704 fix, post-#146): uses
/// `std.mem.sliceTo(ptr, 0)` which scans the C string up to the first
/// NUL — no `@ptrCast` and no `[*:0]` re-typing. The earlier
/// `std.mem.spanZ` call was removed in Zig 0.14+ and would not
/// compile under the 0.15.1 CI pin.
pub fn toolIs(tool_name: [*c]const u8, expected: []const u8) bool {
const s = std.mem.span(@as([*:0]const u8, @ptrCast(tool_name)));
const s = std.mem.sliceTo(tool_name, 0);
return std.mem.eql(u8, s, expected);
}

Expand Down Expand Up @@ -124,19 +130,19 @@ test "writeResult: empty body" {
}

test "toolIs: matches and rejects" {
const name: [*:0]const u8 = "foo";
try std.testing.expect(toolIs(@ptrCast(name), "foo"));
try std.testing.expect(!toolIs(@ptrCast(name), "bar"));
try std.testing.expect(!toolIs(@ptrCast(name), "foobar"));
try std.testing.expect(!toolIs(@ptrCast(name), "fo"));
const name: [*c]const u8 = "foo";
try std.testing.expect(toolIs(name, "foo"));
try std.testing.expect(!toolIs(name, "bar"));
try std.testing.expect(!toolIs(name, "foobar"));
try std.testing.expect(!toolIs(name, "fo"));
}

test "invokeArgsNull: detects each null slot" {
var buf: [4]u8 = undefined;
var len: usize = 4;
const name: [*:0]const u8 = "x";
try std.testing.expect(!invokeArgsNull(@ptrCast(name), &buf, &len));
const name: [*c]const u8 = "x";
try std.testing.expect(!invokeArgsNull(name, &buf, &len));
try std.testing.expect(invokeArgsNull(null, &buf, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), null, &len));
try std.testing.expect(invokeArgsNull(@ptrCast(name), &buf, null));
try std.testing.expect(invokeArgsNull(name, null, &len));
try std.testing.expect(invokeArgsNull(name, &buf, null));
}
Loading
Loading