fix: stop parsing printf buffer after invalid string index
- IGC stores invalid string index at the end of printf buffer, invalid index is equal to (int32_t)-1 extended to (char*) - printKernelOutput() should not parse buffer after invalid index was found to avoid invalid string pointer dereference Related-To: NEO-5753 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
parent
1bbaffc31b
commit
f8b375cae5
|
@ -45,6 +45,9 @@ void PrintFormatter::printKernelOutput(const std::function<void(char *)> &print)
|
|||
while (currentOffset + sizeof(char *) <= printfOutputBufferSize) {
|
||||
char *formatString = nullptr;
|
||||
read(&formatString);
|
||||
if (formatString == reinterpret_cast<char *>(static_cast<uintptr_t>(0xffffffff))) {
|
||||
break;
|
||||
}
|
||||
if (formatString != nullptr) {
|
||||
printString(formatString, print);
|
||||
}
|
||||
|
|
|
@ -985,6 +985,25 @@ TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringAnd2StringsT
|
|||
EXPECT_STREQ(expectedOutput, output);
|
||||
}
|
||||
|
||||
TEST_F(PrintFormatterTest, GivenNoStringMapAndInvalidStringIndexStoredWhenPrintingOutputThenBufferParsingStopsAfterInvalidIndex) {
|
||||
printFormatter.reset(new PrintFormatter(static_cast<uint8_t *>(data->getUnderlyingBuffer()), printfBufferSize, true));
|
||||
|
||||
const char *string1 = "str1";
|
||||
storeData(string1);
|
||||
const int invalidIndex = -1;
|
||||
const int zero = 0;
|
||||
storeData(invalidIndex);
|
||||
storeData(zero);
|
||||
|
||||
const char *string2 = "str2";
|
||||
storeData(string2);
|
||||
|
||||
const char *expectedOutput = "str1";
|
||||
char output[maxPrintfOutputLength];
|
||||
printFormatter->printKernelOutput([&output](char *str) { strncpy_s(output, maxPrintfOutputLength, str, maxPrintfOutputLength - 1); });
|
||||
EXPECT_STREQ(expectedOutput, output);
|
||||
}
|
||||
|
||||
TEST_F(PrintFormatterTest, GivenTypeSmallerThan4BThenItIsReadAs4BValue) {
|
||||
printFormatter.reset(new PrintFormatter(static_cast<uint8_t *>(data->getUnderlyingBuffer()), printfBufferSize, true));
|
||||
const char *formatString = "%c %hd %d";
|
||||
|
|
Loading…
Reference in New Issue