Skip to content

Commit bbb843d

Browse files
authored
[UR][CUDA][HIP] Fix UR_PROGRAM_BUILD_INFO_LOG query (#18678)
This query was using `strnlen` on an uninitialized char array so it may return an incorrect length for the build log. This occasionally resulted in uninitialized data being printed to the user.
1 parent f80661e commit bbb843d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

unified-runtime/source/adapters/cuda/program.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ struct ur_program_handle_t_ : ur::cuda::handle_base {
5353
KernelReqdWorkGroupSizeMD{}, KernelMaxWorkGroupSizeMD{},
5454
KernelMaxLinearWorkGroupSizeMD{}, KernelReqdSubGroupSizeMD{} {
5555
urContextRetain(Context);
56+
57+
// When the log is queried we use strnlen(InfoLog), so it needs to be
58+
// initialized like this when it's empty to correctly return 0.
59+
InfoLog[0] = '\0';
5660
}
5761

5862
~ur_program_handle_t_() { urContextRelease(Context); }

unified-runtime/source/adapters/hip/program.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ struct ur_program_handle_t_ : ur::hip::handle_base {
5252
RefCount{1}, Context{Ctxt}, Device{Device}, KernelReqdWorkGroupSizeMD{},
5353
KernelReqdSubGroupSizeMD{} {
5454
urContextRetain(Context);
55+
56+
// When the log is queried we use strnlen(InfoLog), so it needs to be
57+
// initialized like this when it's empty to correctly return 0.
58+
InfoLog[0] = '\0';
5559
}
5660

5761
~ur_program_handle_t_() { urContextRelease(Context); }

unified-runtime/test/conformance/program/urProgramGetBuildInfo.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ TEST_P(urProgramGetBuildInfoTest, SuccessOptions) {
5555
}
5656

5757
TEST_P(urProgramGetBuildInfoTest, SuccessLog) {
58-
UUR_KNOWN_FAILURE_ON(uur::CUDA{});
59-
6058
size_t property_size = 0;
6159
const ur_program_build_info_t property_name = UR_PROGRAM_BUILD_INFO_LOG;
6260

0 commit comments

Comments
 (0)