From 1e8f8da0d91a9c39ded86f07f34c7aa486180c5c Mon Sep 17 00:00:00 2001 From: foreman Date: Fri, 19 Apr 2019 09:49:37 -0400 Subject: [PATCH] P4 to Git Change 1772193 by mshivama@mshivama_tf on 2019/04/19 09:39:39 SWDEV-187020 - Basic "Hello World" Tensorflow program fails to execute on HIP/VDI/PAL/LINUX the API hiDeviceGetName() should pass the length of device name as argument to strncpy() instead of total (dest) memory size which is being passed to it by its caller. Also, bit of a code clean-up. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#18 edit [ROCm/hip commit: 7a1d02c8a1071850b227fb5a509870a5508d8333] --- projects/hip/api/hip/hip_device.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/hip/api/hip/hip_device.cpp b/projects/hip/api/hip/hip_device.cpp index 6e103e2d40..ae4ee89ccf 100644 --- a/projects/hip/api/hip/hip_device.cpp +++ b/projects/hip/api/hip/hip_device.cpp @@ -110,15 +110,19 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) { HIP_RETURN(hipErrorInvalidDevice); } - if (name == nullptr) { + if (name == nullptr || len <= 0) { HIP_RETURN(hipErrorInvalidValue); } auto* deviceHandle = g_devices[device]->devices()[0]; const auto& info = deviceHandle->info(); + const auto nameLen = ::strlen(info.boardName_); - len = ((cl_uint)len < ::strlen(info.boardName_)) ? len : 128; - ::strncpy(name, info.boardName_, len); + if (nameLen > (cl_uint)len) { + HIP_RETURN(hipErrorInvalidValue); + } + + ::strncpy(name, info.boardName_, nameLen); HIP_RETURN(hipSuccess); }