From 4c7b6aee241c4b105ece72e4eb96912799928ba4 Mon Sep 17 00:00:00 2001 From: "Zhao, Maosu" Date: Wed, 10 Dec 2025 06:27:00 +0100 Subject: [PATCH] [DevSAN] Fix crash caused by failing to check for a empty program --- .../loader/layers/sanitizer/msan/msan_ddi.cpp | 14 +++++++++----- .../loader/layers/sanitizer/tsan/tsan_ddi.cpp | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp b/unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp index 6e3cca8490b2b..178aff3050481 100644 --- a/unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp +++ b/unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp @@ -367,9 +367,11 @@ ur_result_t urProgramLink( auto UrRes = pfnProgramLink(hContext, count, phPrograms, pOptions, phProgram); if (UrRes != UR_RESULT_SUCCESS) { - auto Devices = GetDevices(hContext); - PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size()); - UR_CALL(getMsanInterceptor()->insertProgram(*phProgram)); + if (*phProgram) { + auto Devices = GetDevices(hContext); + PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size()); + UR_CALL(getMsanInterceptor()->insertProgram(*phProgram)); + } return UrRes; } @@ -405,8 +407,10 @@ ur_result_t urProgramLinkExp( auto UrRes = pfnProgramLinkExp(hContext, numDevices, phDevices, flags, count, phPrograms, pOptions, phProgram); if (UrRes != UR_RESULT_SUCCESS) { - PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices); - UR_CALL(getMsanInterceptor()->insertProgram(*phProgram)); + if (*phProgram) { + PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices); + UR_CALL(getMsanInterceptor()->insertProgram(*phProgram)); + } return UrRes; } diff --git a/unified-runtime/source/loader/layers/sanitizer/tsan/tsan_ddi.cpp b/unified-runtime/source/loader/layers/sanitizer/tsan/tsan_ddi.cpp index e03e82a62bb62..a5c9d887d6cf5 100644 --- a/unified-runtime/source/loader/layers/sanitizer/tsan/tsan_ddi.cpp +++ b/unified-runtime/source/loader/layers/sanitizer/tsan/tsan_ddi.cpp @@ -197,9 +197,11 @@ ur_result_t urProgramLink( auto UrRes = getContext()->urDdiTable.Program.pfnLink( hContext, count, phPrograms, pOptions, phProgram); if (UrRes != UR_RESULT_SUCCESS) { - auto Devices = GetDevices(hContext); - PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size()); - UR_CALL(getTsanInterceptor()->insertProgram(*phProgram)); + if (*phProgram) { + auto Devices = GetDevices(hContext); + PrintUrBuildLogIfError(UrRes, *phProgram, Devices.data(), Devices.size()); + UR_CALL(getTsanInterceptor()->insertProgram(*phProgram)); + } return UrRes; } UR_CALL(getTsanInterceptor()->insertProgram(*phProgram)); @@ -364,8 +366,10 @@ ur_result_t urProgramLinkExp( hContext, numDevices, phDevices, flags, count, phPrograms, pOptions, phProgram); if (UrRes != UR_RESULT_SUCCESS) { - PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices); - UR_CALL(getTsanInterceptor()->insertProgram(*phProgram)); + if (*phProgram) { + PrintUrBuildLogIfError(UrRes, *phProgram, phDevices, numDevices); + UR_CALL(getTsanInterceptor()->insertProgram(*phProgram)); + } return UrRes; }