Commit 4f97333
authored
Fix use-after-free in ParsedConfigCache for short config strings (#13078)
- 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.1 parent c52cddf commit 4f97333
2 files changed
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
933 | 933 | | |
934 | 934 | | |
935 | 935 | | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
936 | 942 | | |
937 | 943 | | |
938 | 944 | | |
| |||
958 | 964 | | |
959 | 965 | | |
960 | 966 | | |
961 | | - | |
| 967 | + | |
962 | 968 | | |
963 | 969 | | |
964 | 970 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
789 | | - | |
| 789 | + | |
| 790 | + | |
790 | 791 | | |
791 | 792 | | |
792 | 793 | | |
793 | | - | |
794 | | - | |
| 794 | + | |
| 795 | + | |
795 | 796 | | |
796 | | - | |
797 | | - | |
798 | 797 | | |
799 | 798 | | |
800 | 799 | | |
| |||
843 | 842 | | |
844 | 843 | | |
845 | 844 | | |
846 | | - | |
847 | | - | |
848 | 845 | | |
849 | 846 | | |
850 | 847 | | |
| |||
0 commit comments