Files
CMake/Tests/RunCMake/Configure/CacheVarHelpString.cmake
Nikita Nemkin 637a0f7ed4 cmCacheManager: Prevent corruption from multiline help strings
Corruption happens when a multiline help string starts with
a newline. This causes an overflow in substr() and the whole,
unescaped help string is written to the cache file.

Multiline strings are escaped line by line. The fix is to start
searching for line break points from position 1. A break point
at zero, which triggers the overflow, could only produce
a redundant empty line.

Fixes: #9098
2025-02-05 01:26:11 +05:00

22 lines
544 B
CMake

# Various newline possibilities
set(help_strings
"\n"
"\n\n\n"
"\n \n"
"\nline1"
"line1\n"
"\nline1\n"
"line1\nline2\nline3"
"\nline1\nline2\nline3\n"
"
line line line line line line line line line line line line line line line line
line line line line line line line line line line line line line line line line
line line line line line line line line line line line line line line line line"
)
foreach(help IN LISTS help_strings)
string(SHA1 name "${help}")
set("${name}" "" CACHE STRING "${help}" FORCE)
endforeach()