Add slot bounds check and unit tests for pluginsd_parser - #22598
Merged
Conversation
- Introduced `PLUGINSD_SLOT_MAX` to define maximum supported slot value. - Added bounds checking to ignore invalid slot values exceeding the defined maximum. - Implemented `pluginsd_parser_unittest_slot_bounds` to validate slot parsing logic. - Updated error logging for invalid slot scenarios to improve debugging clarity.
- Replaced single `PLUGINSD_SLOT_MAX` with `PLUGINSD_CHART_SLOT_MAX` and `PLUGINSD_DIMENSION_SLOT_MAX` for separate chart and dimension slot limits. - Updated `pluginsd_parse_rrd_slot` to accept a maximum slot parameter for flexible slot validation. - Added unit tests to validate parsing logic with new slot bounds. - Adjusted error logging for invalid slots to reflect the updated configurable limits.
Contributor
There was a problem hiding this comment.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Plugin as Plugin/Child
participant Parser as pluginsd Parser
participant Log as Log System
participant Lookup as Normal Lookup Path
participant Cache as Slot Cache
Note over Plugin,Cache: SLOT validation flow for streaming/pluginsd data
Plugin->>Parser: CLIENT (sends BEGIN/SET/CHART/DIMENSION command with SLOT: value)
Parser->>Parser: Parse SLOT:xxx from command words
alt Parsed SLOT <= max_slot
Note over Parser: SLOT valid (0 to max_slot)
Parser->>Parser: Use as cache index
Parser->>Cache: Access slot N
Cache-->>Parser: Cached data
Parser->>Lookup: Process via slot path
else Parsed SLOT > max_slot or invalid
Note over Parser: SLOT out of range (e.g., huge or > 1,000,000 / 65,535)
Parser->>Log: rate-limited warning: "ignoring invalid SLOT value"
Parser->>Parser: Set slot = 0 (safe fallback)
Parser->>Lookup: Process via normal (uncached) lookup path
Lookup-->>Parser: Data handled correctly
end
Note over Parser,Lookup: Two distinct max_slot constants applied by command type:
Parser->>Parser: CHART/SET/BEGIN commands → PLUGINSD_CHART_SLOT_MAX (1,000,000)
Parser->>Parser: DIMENSION/SET commands → PLUGINSD_DIMENSION_SLOT_MAX (65,535)
Note over Plugins,Lookup: Replication flow (separate path)
Plugin->>Parser: Sends replay_begin / replay_set / replay_rrddim
Parser->>Parser: Same slot validation applied
alt Valid SLOT
Parser->>Cache: Use slot index
else Invalid SLOT
Parser->>Log: Rate-limited warning
Parser->>Lookup: Fallback to normal path
end
stelfrag
marked this pull request as ready for review
June 1, 2026 09:23
stelfrag
marked this pull request as draft
June 1, 2026 09:24
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the pluginsd/streaming parser against malformed or malicious SLOT: values by adding per-command upper bounds and unit tests, preventing sparse cache allocations and potential crashes/corruption while still processing incoming data via the normal lookup path.
Changes:
- Add
PLUGINSD_CHART_SLOT_MAX(1,000,000) andPLUGINSD_DIMENSION_SLOT_MAX(65,535) and pass the appropriate bound to eachSLOT:-aware command/parser path. - Update replication replay parsing to apply the same slot bounds.
- Add unit tests covering in-range slots and out-of-range behavior for both chart and dimension limits.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/plugins.d/pluginsd_internals.h |
Updates slot parsing helper to accept a max bound and reject oversized slot values with rate-limited warnings. |
src/plugins.d/pluginsd_parser.h |
Introduces chart/dimension slot maximum constants used by the parser. |
src/plugins.d/pluginsd_parser.c |
Applies per-command max slot limits and adds unit tests validating slot bound behavior. |
src/plugins.d/pluginsd_replication.c |
Applies the same bounded slot parsing to replication replay commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…arser - Extended `pluginsd_parser_unittest_slot_bounds` with additional test cases for invalid, boundary, and overflow slots. - Added allocation overflow guard in `prd_array_create` for safer memory handling. - Improved `pluginsd_parse_rrd_slot` logic with detailed comments to clarify slot parsing behavior and edge cases.
…ittest_slot_bounds` - Added a guard to ensure `max_slot >= 1` to prevent underflow in boundary cases. - Removed unnecessary `- 1` from `snprintfz` size calculations for cleaner logic.
- Updated behavior for `slot < 1` to specify unique downstream handling for charts and dimensions. - Improved comments to better explain fallback logic and slot path scenarios.
|
ilyam8
approved these changes
Jun 8, 2026
Merged
Ferroin
pushed a commit
that referenced
this pull request
Jul 15, 2026
* Add slot bounds check and unit tests for pluginsd_parser - Introduced `PLUGINSD_SLOT_MAX` to define maximum supported slot value. - Added bounds checking to ignore invalid slot values exceeding the defined maximum. - Implemented `pluginsd_parser_unittest_slot_bounds` to validate slot parsing logic. - Updated error logging for invalid slot scenarios to improve debugging clarity. * Increase slot limits and refactor slot handling in pluginsd_parser - Replaced single `PLUGINSD_SLOT_MAX` with `PLUGINSD_CHART_SLOT_MAX` and `PLUGINSD_DIMENSION_SLOT_MAX` for separate chart and dimension slot limits. - Updated `pluginsd_parse_rrd_slot` to accept a maximum slot parameter for flexible slot validation. - Added unit tests to validate parsing logic with new slot bounds. - Adjusted error logging for invalid slots to reflect the updated configurable limits. * Add slot bounds checks, unit tests, and overflow guard for pluginsd_parser - Extended `pluginsd_parser_unittest_slot_bounds` with additional test cases for invalid, boundary, and overflow slots. - Added allocation overflow guard in `prd_array_create` for safer memory handling. - Improved `pluginsd_parse_rrd_slot` logic with detailed comments to clarify slot parsing behavior and edge cases. * Add `max_slot` bounds check in `pluginsd_parse_rrd_slot` to ensure safety * Add bounds check and improve `snprintfz` usage in `pluginsd_parser_unittest_slot_bounds` - Added a guard to ensure `max_slot >= 1` to prevent underflow in boundary cases. - Removed unnecessary `- 1` from `snprintfz` size calculations for cleaner logic. * Clarify handling of invalid slots in `pluginsd_internals`: - Updated behavior for `slot < 1` to specify unique downstream handling for charts and dimensions. - Improved comments to better explain fallback logic and slot path scenarios. (cherry picked from commit 883928b)
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.



Summary
This PR puts sensible upper limits on those values.
Summary by cubic
Adds slot bounds checking in the pluginsd parser to prevent crashes from oversized SLOT values, plus a guard against array allocation overflows. Clarifies fallback behavior when slots are invalid so charts and dimensions keep working without data loss.
Bug Fixes
max_slotinpluginsd_parse_rrd_slot(must fitssize_t) and treat over-limit values as uncached with a rate-limited warning.slot < 1handling: charts fall back to id lookup; dimensions use the non-slotted path.prd_array_create.Tests
max_slot >= 1to prevent underflow in boundary tests and simplifysnprintfzusage.Written for commit 9f9a178. Summary will update on new commits.