mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Limit access to the printf buffer
Change-Id: Ic212f66ebedc374316c4ad8e32b708ae445f2276 Signed-off-by: Koska <andrzej.koska@intel.com> Related-To: NEO-4595
This commit is contained in:
@ -269,6 +269,21 @@ TEST_P(PrintfUint32Test, GivenPrintfFormatWhenConatinsUintThenInstertValueIntoSt
|
||||
EXPECT_STREQ(referenceOutput, actualOutput);
|
||||
}
|
||||
|
||||
TEST_P(PrintfUint32Test, GivenPrintfFormatWhenBufferSizeExceedsPrintfBufferCapacityThenUseSmallerValue) {
|
||||
auto input = GetParam();
|
||||
printFormatter = std::unique_ptr<PrintFormatter>(new PrintFormatter(static_cast<uint8_t *>(data->getUnderlyingBuffer()), 0, is32bit, kernelInfo->patchInfo.stringDataMap));
|
||||
|
||||
auto stringIndex = injectFormatString(input.format);
|
||||
storeData(stringIndex);
|
||||
injectValue(input.value);
|
||||
|
||||
char referenceOutput[PrintFormatter::maxPrintfOutputLength] = "";
|
||||
char actualOutput[PrintFormatter::maxPrintfOutputLength] = "";
|
||||
printFormatter->printKernelOutput([&actualOutput](char *str) { strncpy_s(actualOutput, PrintFormatter::maxPrintfOutputLength, str, PrintFormatter::maxPrintfOutputLength); });
|
||||
|
||||
EXPECT_STREQ(referenceOutput, actualOutput);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(PrintfUint32Test,
|
||||
PrintfUint32Test,
|
||||
::testing::ValuesIn(uintValues));
|
||||
|
@ -25,7 +25,9 @@ void PrintFormatter::printKernelOutput(const std::function<void(char *)> &print)
|
||||
currentOffset = 0;
|
||||
|
||||
// first 4 bytes of the buffer store the actual size of data that was written by printf from within EUs
|
||||
read(&printfOutputBufferSize);
|
||||
uint32_t printfOutputBufferSizeRead = 0;
|
||||
read(&printfOutputBufferSizeRead);
|
||||
printfOutputBufferSize = std::min(printfOutputBufferSizeRead, printfOutputBufferSize);
|
||||
|
||||
uint32_t stringIndex = 0;
|
||||
while (currentOffset + 4 <= printfOutputBufferSize) {
|
||||
|
Reference in New Issue
Block a user