Skip to content

Conversation

@OxBat
Copy link

@OxBat OxBat commented Jan 27, 2026

Summary

I identified a Denial of Service vulnerability in OptionConverter::substVars.
The component handles variable substitution (e.g., ${key}) recursively.

The Issues:

  1. Stack Overflow (Crash): substVarsSafely is recursive but had no depth limit. A configuration with deeply nested variables (e.g., 20,000 levels) caused a Segmentation Fault.
  2. Algorithmic Complexity (Freeze): The cycle detection logic used a linked list (LogStringChain) that required traversing the parent chain at every step, resulting in O(N^2) complexity.

The Fix:
I refactored the internal substVarsSafely function:

  1. Replaced the custom LogStringChain linked list with a std::vector<LogString> for history tracking (faster lookup).
  2. Added a MAX_SUBST_DEPTH (20). If recursion exceeds this depth, it stops and logs a warning, preventing the crash.

…ic Complexity)

The variable substitution logic lacked a recursion depth limit, leading to
Stack Overflow crashes with deeply nested variables.
The cycle detection was also implemented using a linked list with O(N^2) complexity.
This patch replaces the linked list with a std::vector and enforces a recursion depth limit of 20.
@rm5248
Copy link
Contributor

rm5248 commented Jan 29, 2026

can you add a unit test to ensure that this is working correctly? This unit test can be added to the already existing optioncovertertestcase.cpp

@rm5248
Copy link
Contributor

rm5248 commented Jan 29, 2026

there's actually already a test case for recursive:

void varSubstRecursiveReferenceTest()

Why is that test not failing, or is that test not properly catching the problem that this is fixing?

Added a test to ensure recursion stops at the defined depth limit.
@OxBat
Copy link
Author

OxBat commented Jan 29, 2026

The existing test only catches circular dependencies (loops). My fix targets stack overflows caused by deep recursion without loops.

I just added varSubstDepthLimitTest to cover this specific case (it builds a chain of 25 items to ensure we stop gracefully at the limit).

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.

2 participants