Skip to content

Fix use-after-free in ParsedConfigCache for short config strings#13078

Open
maskit wants to merge 1 commit intoapache:masterfrom
maskit:fix_targeted_cache_control
Open

Fix use-after-free in ParsedConfigCache for short config strings#13078
maskit wants to merge 1 commit intoapache:masterfrom
maskit:fix_targeted_cache_control

Conversation

@maskit
Copy link
Copy Markdown
Member

@maskit maskit commented Apr 9, 2026

  • Fix use-after-free in ParsedConfigCache when config values are short enough for std::string SSO (Small String Optimization)
  • ParsedValue::parse() returned by value, and emplace moved it into the map — relocating the SSO inline buffer while string_views in TargetedCacheControlHeaders::headers[] still pointed to the old address
  • Make ParsedValue non-movable and use try_emplace + parse_into() so parsing happens directly in the map node
  • Also fixes the same class of bug for HostResData::conf_value and HttpStatusCodeList::conf_value pointers

Reproducer: configure conf_remap with a short targeted header value like ACME-Cache-Control (18 chars, within libc++ SSO threshold of 22). The string_views in the per-transaction override become dangling, causing incorrect cache behavior.

The SSO threshold varies by standard library — libc++ (macOS/clang): 22 bytes, libstdc++ (GCC/Linux): 15 bytes. A value like ACME-Cache-Control (18 chars) triggers SSO on libc++ but uses heap allocation on libstdc++, where the buffer pointer survives the move. This is why the bug may reproduce on macOS but not on Linux CI with GCC.

- Fix use-after-free in ParsedConfigCache when config values are short enough for std::string SSO (Small String Optimization)
- ParsedValue::parse() returned by value, and emplace moved it into the map — relocating the SSO inline buffer while string_views in TargetedCacheControlHeaders::headers[] still pointed to the old address
- Make ParsedValue non-movable and use try_emplace + parse_into() so parsing happens directly in the map node
- Also fixes the same class of bug for HostResData::conf_value and HttpStatusCodeList::conf_value pointers

Reproducer: configure conf_remap with a short targeted header value like ACME-Cache-Control (18 chars, within libc++ SSO threshold of 22). The string_views in the per-transaction override become dangling, causing incorrect cache
behavior.

The SSO threshold varies by standard library — libc++ (macOS/clang): 22 bytes, libstdc++ (GCC/Linux): 15 bytes. A value like ACME-Cache-Control (18 chars) triggers SSO on libc++ but uses heap allocation on libstdc++, where the buffer
pointer survives the move. This is why the bug may reproduce on macOS but not on Linux CI with GCC.
@maskit maskit added this to the 11.0.0 milestone Apr 9, 2026
@maskit maskit self-assigned this Apr 9, 2026
@maskit maskit added the Bug label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant