From 1d74b9271af0f43bda86cda5abc8f472502b6012 Mon Sep 17 00:00:00 2001 From: Julia Jiang Date: Thu, 23 Jun 2022 15:33:22 -0400 Subject: [PATCH] SWDEV-342013,SWDEV-342014 - Update validation on hipDeviceGet and hipDeviceGetName Change-Id: I719da6169ce9f505449e07775cb94a5718f79ca3 [ROCm/clr commit: 3415f0a56e99586344ebe772ffa9060157b4d2f2] --- projects/clr/hipamd/src/hip_device.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/src/hip_device.cpp b/projects/clr/hipamd/src/hip_device.cpp index 8c72bd0d7c..b4cf8dd22a 100644 --- a/projects/clr/hipamd/src/hip_device.cpp +++ b/projects/clr/hipamd/src/hip_device.cpp @@ -121,9 +121,14 @@ void ihipDestroyDevice() { } hipError_t ihipDeviceGet(hipDevice_t* device, int deviceId) { - if (deviceId < 0 || static_cast(deviceId) >= g_devices.size() || device == nullptr) { + if (device == nullptr) { + return hipErrorInvalidValue; + } + + if (deviceId < 0 || static_cast(deviceId) >= g_devices.size()) { return hipErrorInvalidDevice; } + *device = deviceId; return hipSuccess; } @@ -213,7 +218,7 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) { // Make sure that the size of `dest` is big enough to hold `src` including // trailing zero byte - if (nameLen > (cl_uint)(len - 1)) { + if (nameLen <= 0) { HIP_RETURN(hipErrorInvalidValue); }