From 23eb67ce874e08a5bbc0ea1956b0357880034d24 Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Tue, 27 May 2025 10:29:53 +0100 Subject: [PATCH] [UR][CUDA][HIP] Fix UR_PROGRAM_BUILD_INFO_LOG query 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. --- unified-runtime/source/adapters/cuda/program.hpp | 4 ++++ unified-runtime/source/adapters/hip/program.hpp | 4 ++++ .../test/conformance/program/urProgramGetBuildInfo.cpp | 2 -- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/unified-runtime/source/adapters/cuda/program.hpp b/unified-runtime/source/adapters/cuda/program.hpp index b6478a4973d58..7371283c274d1 100644 --- a/unified-runtime/source/adapters/cuda/program.hpp +++ b/unified-runtime/source/adapters/cuda/program.hpp @@ -53,6 +53,10 @@ struct ur_program_handle_t_ : ur::cuda::handle_base { KernelReqdWorkGroupSizeMD{}, KernelMaxWorkGroupSizeMD{}, KernelMaxLinearWorkGroupSizeMD{}, KernelReqdSubGroupSizeMD{} { urContextRetain(Context); + + // When the log is queried we use strnlen(InfoLog), so it needs to be + // initialized like this when it's empty to correctly return 0. + InfoLog[0] = '\0'; } ~ur_program_handle_t_() { urContextRelease(Context); } diff --git a/unified-runtime/source/adapters/hip/program.hpp b/unified-runtime/source/adapters/hip/program.hpp index 38857f635bcfd..c94818c6c43ab 100644 --- a/unified-runtime/source/adapters/hip/program.hpp +++ b/unified-runtime/source/adapters/hip/program.hpp @@ -52,6 +52,10 @@ struct ur_program_handle_t_ : ur::hip::handle_base { RefCount{1}, Context{Ctxt}, Device{Device}, KernelReqdWorkGroupSizeMD{}, KernelReqdSubGroupSizeMD{} { urContextRetain(Context); + + // When the log is queried we use strnlen(InfoLog), so it needs to be + // initialized like this when it's empty to correctly return 0. + InfoLog[0] = '\0'; } ~ur_program_handle_t_() { urContextRelease(Context); } diff --git a/unified-runtime/test/conformance/program/urProgramGetBuildInfo.cpp b/unified-runtime/test/conformance/program/urProgramGetBuildInfo.cpp index 9d956f3606f58..a01e4251828c0 100644 --- a/unified-runtime/test/conformance/program/urProgramGetBuildInfo.cpp +++ b/unified-runtime/test/conformance/program/urProgramGetBuildInfo.cpp @@ -55,8 +55,6 @@ TEST_P(urProgramGetBuildInfoTest, SuccessOptions) { } TEST_P(urProgramGetBuildInfoTest, SuccessLog) { - UUR_KNOWN_FAILURE_ON(uur::CUDA{}); - size_t property_size = 0; const ur_program_build_info_t property_name = UR_PROGRAM_BUILD_INFO_LOG;