Skip to content

Fix CVE-2025-67125: prevent signed counter overflow in LeafPattern::match#168

Open
thesmartshadow wants to merge 1 commit intodocopt:masterfrom
thesmartshadow:fix/cwe190-counter-overflow
Open

Fix CVE-2025-67125: prevent signed counter overflow in LeafPattern::match#168
thesmartshadow wants to merge 1 commit intodocopt:masterfrom
thesmartshadow:fix/cwe190-counter-overflow

Conversation

@thesmartshadow
Copy link

This PR fixes a signed integer overflow in LeafPattern::match when merging repeated option occurrences.

What was happening

The previous implementation performed an unchecked signed addition when combining a newly matched occurrence with an already collected counter value.

In practice, if the existing counter reached LONG_MAX, the next occurrence would trigger signed overflow (LONG_MAX + 1), which could lead to wrapped or otherwise invalid counter semantics.

What this change does

  • introduces guarded arithmetic for counter merging
  • prevents signed overflow during repeated-option count updates
  • defensively avoids negative post-merge counter states that could be interpreted in unexpected ways

Why this matters

This keeps the counter logic stable and predictable, especially for applications that rely on occurrence counts for limits, toggles, or other decision-making logic.

Notes

  • the fix is intentionally small and focused on the vulnerable merge path
  • project build was rechecked after the change
  • related issue: CVE-2025-67125 / CWE-190

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant