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:
Tyler Yankee
2026-05-16 15:57:34 -04:00
parent afad360df9
commit 2e55f86bb3
3 changed files with 10 additions and 0 deletions

View File

@@ -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++;
}

View File

@@ -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)

View File

@@ -0,0 +1,2 @@
S107000001020304EE
S1FF000041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414100