Fix uncontrolled recursion in os_xml _ReadElem (issue #1953) a#2175
Merged
atomicturtle merged 1 commit intoossec:mainfrom Jan 24, 2026
Merged
Fix uncontrolled recursion in os_xml _ReadElem (issue #1953) a#2175atomicturtle merged 1 commit intoossec:mainfrom
atomicturtle merged 1 commit intoossec:mainfrom
Conversation
… add regression test
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates the uncontrolled recursion vulnerability in the os_xml XML parser (_ReadElem) that could previously cause stack overflows (CVE-2021-28040 / issue #1953), and adds a regression test to guard against regressions in recursion handling.
Changes:
- Extend
_ReadElemto accept arecursion_levelargument, enforce a maximum recursion depth of 1024, and refactor local XML parsing buffers from stack-allocated arrays to heap-allocated buffers with centralized cleanup to avoid stack overflows and leaks on error paths. - Update
OS_ReadXMLto seed the recursion depth (_ReadElem(..., 0)) and adjust internal_ReadElemcall sites to propagate the current depth correctly during nested element parsing. - Add a standalone regression test (
issue_1953_xml_recursion.c) that constructs an XML document with 2000 nested elements and verifies thatOS_ReadXMLfails with the expected "Max recursion level reached" error instead of crashing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/os_xml/os_xml.c | Adds recursion depth tracking and a hard limit in _ReadElem, switches large per-frame buffers to heap allocation with consistent cleanup via a common end: label, and updates callers to pass the recursion level. |
| src/tests/regressions/issue_1953_xml_recursion.c | New regression test program that generates deeply nested XML, invokes OS_ReadXML, and asserts that parsing fails with the specific recursion-limit error message rather than succeeding or crashing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Resolves issue #1953 and CVE-2021-28040