Repository navigation
feat(manifests): catch an unchecked copy into a member buffer - #21
Merged
Merged
Conversation
Portll
force-pushed
the
fix/cw-unchecked-copy-detector-20261206
branch
from
December 6, 2026 06:36
0ee6b58 to
c6f3929
Compare
cw-bounds-check-sum-overflow matches an insufficient check. A function with no check at all has no sum to match, and reads as clean. On SDL Hercules-390 three write exits copied a client-supplied offset and length into a fixed device buffer. The sum rule was silent on two of them, and on the third it fired on the update-range line rather than the copy. Scoped to a struct member destination: a local array is the registry's unbounded-copy-to-stack-buffer, while a member buffer is the device or context buffer a caller fills, which is the shape that goes unchecked when the contract is "the caller validates". A constant length is excluded because it cannot be attacker-sized. Measured on the Hercules tree: 6 hits, 3 of them the real defect, and 3 bounded copies whose guard is a clamp or a capacity call rather than a comparison. LOW confidence is the honest reading of that ratio. The message says a hit is a prompt to read the function, not a verdict. Refs: cw-hercules-scan-20261129 F6
Portll
force-pushed
the
fix/cw-unchecked-copy-detector-20261206
branch
from
December 6, 2026 06:39
c6f3929 to
66586c2
Compare
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.
Why
cw-bounds-check-sum-overflowmatches an insufficient check — a sum that can wrap. A function with no check at all has no sum to match, so it reads as clean. That is a silent clean over the exact class the rule was written for.Found while scanning SDL Hercules-390 (
develop@8ab5c3f1). Four DASD write exits copy a client-supplied offset and length into a fixed device buffer:ckd_dasd_update_track(ckddasd.c:1234)off + len > bufoffhifba_dasd_update_blkgrp(fbadasd.c:766):771— the update-range line, not the copycfba_write_block(cckddasd.c:1158)cfba64_write_block(cckddasd64.c:888)The two compressed-FBA exits are the gap: no check, so nothing for the sum rule to match.
cfba64_write_blockis the same defect in code with no callers — declared incckddasd.handhexterns.h, never wired into a handler table. A real defect that is not reachable today, which is why the rule firing on it is correct rather than alarming.What it does
cw-unchecked-copy-into-member-buffer— amemcpy/memmoveinto a struct member buffer at a variable offset with a variable length, where no comparison ofoffset + lengthagainst a size appears in the enclosing function.Three deliberate narrowings:
unbounded-copy-to-stack-buffer. A member buffer is the device/context buffer a caller fills — the shape that goes unchecked when the contract is "the caller validates".>,>=,<,<=andsizeofare each excluded, because a check written the other way round is still a check.Precision, measured
On the Hercules tree (201
.c/ 155.h, ~436k lines): 6 hits, 3 of them the real defect.cckddasd.c:1158,cckddasd64.c:888(dead code),fbadasd.c:766dasdload2.h:2468— the guard boundsdlenvsnllen, notoffset + nllenvs the bufferwscnsl.c:139(length clamped byj = 64 - i),wscnsl.c:700(guarded by anensure_bufcapacity call)Both false positives are guards this rule cannot see — a clamp and a capacity call rather than a comparison. That is why it is
confidence: LOWand why the message says a hit is a prompt to read the function, not a verdict.Tests
monitor/test/semgrep-classes.test.mjs— both cases pass:The fixture pairs an unguarded copy (
ruleid) with a guarded one (ok). The guarded case's check is the wrapping form, so that line carries aruleid: cw-bounds-check-sum-overflow— the two rules doing their separate jobs on one function.Caveat worth knowing
Semgrep's C parser is unreliable on this codebase: 92 errors over the tree, including 15 outright syntax errors and partial parses. Under load its default per-file timeout also drops hits —
cckddasd.c:1158disappeared at the default timeout and reappeared at--timeout 120. A file that times out or fails to parse yields no findings, which is the same silent-clean class this rule exists to close. Not fixed here; recorded so the next reader does not read a short result list as a clean tree.Refs:
cw-hercules-scan-20261129F6