fix(ffi): remove unchecked @ptrCast from cartridge shims (CWE-704)#290
Merged
Conversation
Sweeps all 114 vendored copies of cartridge_shim.zig in boj-server — including the canonical shared source ffi/zig/src/cartridge_shim.zig — to the blessed post-#146 idiom: std.mem.sliceTo(tool_name, 0) with [*c]const u8 test locals and no @ptrCast. Mirrors PR #89 in boj-server-cartridges, which is the split-out of these cartridges. Why the casts were redundant, not unsafe: a [*:0]const u8 sentinel pointer coerces implicitly to the [*c]const u8 that toolIs/invokeArgsNull accept, so @ptrCast(name) was a no-op widening — but a C-oriented scanner (Hypatia code_safety/zig_ptr_cast, CWE-704) still flags it as an unchecked pointer type conversion. Typing the local as [*c]const u8 up front removes the finding rather than suppressing it. Also folds in ffi/zig/src/abi_verify.zig (ABI-conformance tests C.6/C.7), which called shim.toolIs/invokeArgsNull via @ptrCast. NOTE: that file was modified in the shared working tree by a concurrent agent; it is included here because it is the identical CWE-704 fix — flag if it should land separately. Verification (zig 0.15.2, the CI-pinned version): - every cartridge_shim.zig compiles and passes `zig test` standalone; - the edited abi_verify C.6/C.7 idiom verified in isolation against the real shim (8/8), since the full `zig build test` graph does not compile under 0.15.2 for reasons unrelated to this change (see below). Out of scope, reported separately: (1) .github/workflows/zig-test.yml has been startup_failure (0s) on main since >=2026-07-09, so this repo's Zig CI validates nothing and this PR's zig-test check cannot pass on any branch; (2) catalogue/guardian/loader/coprocessor/sdp reference the removed std.atomic.Mutex and do not compile under the pinned 0.15.2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🔍 Hypatia Security ScanFindings: 230 issues detected
View findings[
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages-deploy.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/upload-pages-artifact@v3 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/deploy-pages@v4 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in build.yml",
"type": "missing_timeout_minutes",
"file": "build.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in pages-deploy.yml",
"type": "missing_timeout_minutes",
"file": "pages-deploy.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in push-email-notify.yml",
"type": "missing_timeout_minutes",
"file": "push-email-notify.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in scorecard-enforcer.yml",
"type": "missing_timeout_minutes",
"file": "scorecard-enforcer.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in scorecard-enforcer.yml",
"type": "scorecard_publish_with_run_step",
"file": "scorecard-enforcer.yml",
"action": "split_scorecard_publish_job",
"rule_module": "workflow_audit",
"severity": "high"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
🏁 path-claims benchCommit NumbersHost-dependent — compare deltas across commits, not absolute values. |
hyperpolymath
marked this pull request as ready for review
July 21, 2026 12:06
🔍 Hypatia Security ScanFindings: 230 issues detected
View findings[
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages-deploy.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/upload-pages-artifact@v3 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action actions/deploy-pages@v4 needs attention",
"type": "unpinned_action",
"file": "pages.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in build.yml",
"type": "missing_timeout_minutes",
"file": "build.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in pages-deploy.yml",
"type": "missing_timeout_minutes",
"file": "pages-deploy.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in push-email-notify.yml",
"type": "missing_timeout_minutes",
"file": "push-email-notify.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in scorecard-enforcer.yml",
"type": "missing_timeout_minutes",
"file": "scorecard-enforcer.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in scorecard-enforcer.yml",
"type": "scorecard_publish_with_run_step",
"file": "scorecard-enforcer.yml",
"action": "split_scorecard_publish_job",
"rule_module": "workflow_audit",
"severity": "high"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Removes the unchecked
@ptrCastfrom the cartridge FFI shims (CWE-704: Incorrect TypeConversion or Cast) across 115 files.
std.mem.sliceTo(ptr, 0)scans the C string to the first NUL — no@ptrCast, no[*:0]re-typing. The cast asserted a sentinel-terminated type that the
[*c]parameter does notguarantee, so a non-NUL-terminated
tool_namewas undefined behaviour rather than abounded read.
Why now
Secondary benefit: the previous form depended on
std.mem.spanZ/spansemantics thatchanged in Zig 0.14+, so this also unblocks compilation under the CI pin.
Scope
cartridges/*/ffi/cartridge_shim.zigffi/zig/src/cartridge_shim.zig,ffi/zig/src/abi_verify.zig[*c]const u8directly instead of@ptrCast-ing a[*:0]Diff: +1833 / −1149. Merges cleanly against
main(0 conflicts).Note on red checks
Required checks on this PR will report
startup_failurefor reasons unrelated to thischange: this repository has
allowed_actions: selectedwith an emptypatterns_allowed,so every workflow using a non-GitHub-owned action is refused before any job starts (20 of
25 workflows). The sibling
boj-server-cartridgeshasallowed_actions: alland is fullygreen on the same workflow set.
Held as draft until that repository-settings fix lands; the code change itself is
complete and self-contained.