From 74e3617ef8884d64febf03d21eb4f1fc99aa23b0 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Thu, 15 Jun 2017 00:21:47 +0530 Subject: [PATCH] Arguments validation in hipDeviceGetPCIBusId Change-Id: I89770517c3ac94e4bf476344d27c18f03cfcde08 [ROCm/hip commit: d24818bff6e2f202b031e92d0b0f2c27a31757e5] --- projects/hip/src/hip_device.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/projects/hip/src/hip_device.cpp b/projects/hip/src/hip_device.cpp index 05db4c2b30..2bb9970d35 100644 --- a/projects/hip/src/hip_device.cpp +++ b/projects/hip/src/hip_device.cpp @@ -369,12 +369,24 @@ hipError_t hipDeviceGetName(char *name,int len,hipDevice_t device) hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device) { HIP_INIT_API(pciBusId, len, device); - hipError_t e = hipSuccess; - int tempPciBusId = 0; - e = ihipDeviceGetAttribute( &tempPciBusId, hipDeviceAttributePciBusId, device); - if( e == hipSuccess) { - std::string tempPciStr = std::to_string(tempPciBusId); - memcpy( pciBusId , tempPciStr.c_str() , tempPciStr.length() ); + hipError_t e = hipErrorInvalidValue; + int deviceCount = 0; + ihipGetDeviceCount( &deviceCount ); + if((device > deviceCount) || (device < 0)) { + e = hipErrorInvalidDevice; + } else { + if((pciBusId != nullptr) && (len > 0)) { + int tempPciBusId = 0; + e = ihipDeviceGetAttribute( &tempPciBusId, hipDeviceAttributePciBusId, device); + if( e == hipSuccess) { + std::string tempPciStr = std::to_string(tempPciBusId); + if( len < tempPciStr.length()){ + e = hipErrorInvalidValue; + } else { + memcpy( pciBusId , tempPciStr.c_str() , tempPciStr.length() ); + } + } + } } return ihipLogStatus(e); }