libpcp: reject undersized metadata records in __pmLogLoadMeta - #2663
libpcp: reject undersized metadata records in __pmLogLoadMeta#2663kurik wants to merge 1 commit into
Conversation
__pmLogLoadMeta() rejects undersized metadata records qa/2009: exercise __pmLogLoadMeta undersized metadata record rejection Co-authored-by: Cursor <cursoragent@cursor.com>
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds record-length validation to both metadata loaders and introduces QA test 2009, which creates malformed archives and verifies ChangesMetadata validation
Sequence Diagram(s)sequenceDiagram
participant pmdumplog
participant __pmLogLoadMeta
participant metadata_archive
pmdumplog->>__pmLogLoadMeta: load metadata records
__pmLogLoadMeta->>metadata_archive: read crafted record header
metadata_archive-->>__pmLogLoadMeta: undersized length and type
__pmLogLoadMeta-->>pmdumplog: report Corrupted record
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/libpcp/src/logmeta.c`:
- Around line 821-827: Enforce remaining-length bounds before every metadata
field and string read in the loaders’ record-parsing paths, including the checks
around the rlen validation in src/libpcp/src/logmeta.c (lines 821-827) and
src/libpcp3/src/logmeta.c (lines 767-773), rejecting zero or undersized positive
payloads without crossing record or allocation boundaries. Extend qa/2009 (lines
63-75) with total lengths 12 through 19 to cover these cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 8a9f0fa1-1045-44b5-921d-664eb5655ea9
⛔ Files ignored due to path filters (1)
qa/2009.outis excluded by!**/*.out
📒 Files selected for processing (4)
qa/2009qa/groupsrc/libpcp/src/logmeta.csrc/libpcp3/src/logmeta.c
| if (rlen < 0) { | ||
| if (pmDebugOptions.logmeta) | ||
| fprintf(stderr, "__pmLogLoadMeta: record len=%d too small (min %d)\n", | ||
| h.len, (int)(sizeof(__pmLogHdr) + sizeof(int))); | ||
| sts = PM_ERR_LOGREC; | ||
| goto end; | ||
| } |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
Enforce payload bounds consistently in both loaders and QA.
The new check rejects negative rlen, but positive undersized records can still make metadata parsing cross record boundaries or read past allocations.
src/libpcp/src/logmeta.c#L821-L827: add remaining-length checks before every metadata field/string read.src/libpcp3/src/logmeta.c#L767-L773: apply the same bounded parsing contract.qa/2009#L63-L75: add total lengths 12–19 to cover zero and small positive payloads.
📍 Affects 3 files
src/libpcp/src/logmeta.c#L821-L827(this comment)src/libpcp3/src/logmeta.c#L767-L773qa/2009#L63-L75
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/libpcp/src/logmeta.c` around lines 821 - 827, Enforce remaining-length
bounds before every metadata field and string read in the loaders’
record-parsing paths, including the checks around the rlen validation in
src/libpcp/src/logmeta.c (lines 821-827) and src/libpcp3/src/logmeta.c (lines
767-773), rejecting zero or undersized positive payloads without crossing record
or allocation boundaries. Extend qa/2009 (lines 63-75) with total lengths 12
through 19 to cover these cases.
__pmLogLoadMeta() rejects undersized metadata records
qa/2009: exercise __pmLogLoadMeta undersized metadata record rejection