diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index 99e218efad..e6f6d4a95e 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -207,7 +207,14 @@ static uint64_t get_multiplier_from_str(char units_char) { * ": <|*>" */ static uint64_t freq_string_to_int(const std::vector &freq_lines, - bool *is_curr, uint32_t lanes[], int i) { + bool *is_curr, uint32_t lanes[], uint32_t i) { + + assert(i < freq_lines.size()); + if (i >= freq_lines.size()) { + throw amd::smi::rsmi_exception(RSMI_STATUS_INPUT_OUT_OF_BOUNDS, + __FUNCTION__); + } + std::istringstream fs(freq_lines[i]); uint32_t ind; @@ -238,6 +245,10 @@ static uint64_t freq_string_to_int(const std::vector &freq_lines, if (star_str[0] == 'x') { assert(lanes != nullptr && "Lanes are provided but null lanes pointer"); if (lanes) { + if (star_str.substr(1) == "") { + throw amd::smi::rsmi_exception(RSMI_STATUS_NO_DATA, __FUNCTION__); + } + lanes[i] = std::stoi(star_str.substr(1), nullptr); } } @@ -417,6 +428,9 @@ static rsmi_status_t get_dev_mon_value(amd::smi::MonitorTypes type, return errno_to_rsmi_status(ret); } + if (val_str == "") { + return RSMI_STATUS_NO_DATA; + } *val = std::stoi(val_str); return RSMI_STATUS_SUCCESS; @@ -445,6 +459,10 @@ static rsmi_status_t get_dev_mon_value(amd::smi::MonitorTypes type, } assert(amd::smi::IsInteger(val_str)); + if (val_str == "") { + return RSMI_STATUS_NO_DATA; + } + *val = std::stoul(val_str); return RSMI_STATUS_SUCCESS; @@ -1400,6 +1418,11 @@ get_id_name_str_from_line(uint64_t id, std::string ln, THROW_IF_NULLPTR_DEREF(ln_str) *ln_str >> token1; + + if (token1 == "") { + throw amd::smi::rsmi_exception(RSMI_STATUS_NO_DATA, __FUNCTION__); + } + if (std::stoul(token1, nullptr, 16) == id) { int64_t pos = ln_str->tellg(); diff --git a/projects/rocm-smi-lib/src/rocm_smi_device.cc b/projects/rocm-smi-lib/src/rocm_smi_device.cc index a4ba2db753..5a52548ad5 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_device.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_device.cc @@ -664,6 +664,10 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) { case kDevErrCntFeatures: ret = readDevInfoStr(type, &tempStr); RET_IF_NONZERO(ret); + + if (tempStr == "") { + return EINVAL; + } *val = std::stoi(tempStr, 0, 16); break; @@ -681,6 +685,9 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) { case kDevXGMIError: ret = readDevInfoStr(type, &tempStr); RET_IF_NONZERO(ret); + if (tempStr == "") { + return EINVAL; + } *val = std::stoul(tempStr, 0); break; @@ -708,6 +715,9 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) { case kDevFwVersionVcn: ret = readDevInfoStr(type, &tempStr); RET_IF_NONZERO(ret); + if (tempStr == "") { + return EINVAL; + } *val = std::stoul(tempStr, 0, 16); break; diff --git a/projects/rocm-smi-lib/src/rocm_smi_kfd.cc b/projects/rocm-smi-lib/src/rocm_smi_kfd.cc index 32149afebd..ad3c6bfaea 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_kfd.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_kfd.cc @@ -159,6 +159,9 @@ int GetProcessInfo(rsmi_process_info_t *procs, uint32_t num_allocated, return err; } assert(is_number(tmp) && "Unexpected value in pasid file"); + if (!is_number(tmp)) { + return EINVAL; + } procs[*num_procs_found].pasid = std::stoi(tmp); } ++(*num_procs_found); @@ -196,6 +199,10 @@ int GetProcessInfoForPID(uint32_t pid, rsmi_process_info_t *proc) { return err; } assert(is_number(tmp) && "Unexpected value in pasid file"); + + if (!is_number(tmp)) { + return EINVAL; + } proc->pasid = std::stoi(tmp); return 0;