Skip to content

Commit f736d5e

Browse files
authored
[SYCL] Fix a couple of memory corruptions. (#7231)
1. It's UB to construct std::string using nullptr which may happen with mock device images in SYCL unittests 2. Fixed a couple of mock "getInfo" PI APIs that were casting param_value to an incorrect type.
1 parent f2983fc commit f736d5e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

sycl/source/detail/persistent_device_code_cache.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,10 @@ std::string PersistentDeviceCodeCache::getCacheItemPath(
333333
return {};
334334
}
335335

336-
std::string ImgString{(const char *)Img.getRawData().BinaryStart,
337-
Img.getSize()};
336+
std::string ImgString = "";
337+
if (Img.getRawData().BinaryStart)
338+
ImgString.assign((const char *)Img.getRawData().BinaryStart, Img.getSize());
339+
338340
std::string DeviceString{getDeviceIDString(Device)};
339341
std::string SpecConstsString{(const char *)SpecConsts.data(),
340342
SpecConsts.size()};

sycl/unittests/helpers/PiMockPlugin.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ inline pi_result mock_piDeviceGetInfo(pi_device device,
127127
}
128128
case PI_DEVICE_INFO_PARENT_DEVICE: {
129129
if (param_value)
130-
*static_cast<pi_device **>(param_value) = nullptr;
130+
*static_cast<pi_device *>(param_value) = nullptr;
131131
if (param_value_size_ret)
132132
*param_value_size_ret = sizeof(pi_device *);
133133
return PI_SUCCESS;
@@ -407,7 +407,7 @@ inline pi_result mock_piProgramGetInfo(pi_program program,
407407
switch (param_name) {
408408
case PI_PROGRAM_INFO_NUM_DEVICES: {
409409
if (param_value)
410-
*static_cast<size_t *>(param_value) = 1;
410+
*static_cast<unsigned int *>(param_value) = 1;
411411
if (param_value_size_ret)
412412
*param_value_size_ret = sizeof(size_t);
413413
return PI_SUCCESS;

0 commit comments

Comments
 (0)