mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-24 08:47:59 +00:00
cmHexFileConverter: Avoid stack buffer overflow
Prevent overflow on maliciously-crafted Motorola S1 record files which have a maximum line length over the 256-byte maximum.
This commit is contained in:
@@ -45,6 +45,10 @@ static bool OutputBin(FILE* file, char const* buf, unsigned int startIndex,
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
if (outBufCount >= sizeof(outBuf)) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
outBuf[outBufCount] = static_cast<char>(convertedByte & 0xff);
|
||||
outBufCount++;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ else()
|
||||
"file(STRINGS) incorrectly read from srec file [${infile_strings}]")
|
||||
endif()
|
||||
|
||||
# this file is crafted to contain the maximum line length and trigger a buffer
|
||||
# overflow
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/s1-max-length.srec" infile_strings)
|
||||
|
||||
#this file has utf-8 content
|
||||
file(STRINGS test.utf8 infile_strings ENCODING UTF-8)
|
||||
list(LENGTH infile_strings content_len)
|
||||
|
||||
2
Tests/StringFileTest/s1-max-length.srec
Normal file
2
Tests/StringFileTest/s1-max-length.srec
Normal file
@@ -0,0 +1,2 @@
|
||||
S107000001020304EE
|
||||
S1FF000041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414100
|
||||
Reference in New Issue
Block a user