mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 22:43:00 +08:00
Adjust the implementation of strncpy_s() for Linux
This change: - prevents writing memory out of the range of the destination buffer - prevents calling strlen() with non-null terminated c-string - corrects the logic, which validates passed range to proceed when real length fits the destination buffer Related-To: NEO-7264 Signed-off-by: Wrobel, Patryk <patryk.wrobel@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
5bdf758049
commit
dda5b19859
@@ -51,7 +51,7 @@ bool LinuxFirmwareImp::isFirmwareSupported(void) {
|
||||
|
||||
void LinuxFirmwareImp::osGetFwProperties(zes_firmware_properties_t *pProperties) {
|
||||
if (ZE_RESULT_SUCCESS != getFirmwareVersion(osFwType, pProperties)) {
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.c_str(), ZES_STRING_PROPERTY_SIZE - 1);
|
||||
}
|
||||
pProperties->canControl = true; //Assuming that user has permission to flash the firmware
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ ze_result_t LinuxFirmwareImp::getFirmwareVersion(std::string fwType, zes_firmwar
|
||||
std::string fwVersion;
|
||||
ze_result_t result = pFwInterface->getFwVersion(fwType, fwVersion);
|
||||
if (ZE_RESULT_SUCCESS == result) {
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, fwVersion.c_str(), ZES_STRING_PROPERTY_SIZE);
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, fwVersion.c_str(), ZES_STRING_PROPERTY_SIZE - 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
} // namespace L0
|
||||
|
||||
@@ -43,15 +43,15 @@ ze_result_t LinuxFirmwareImp::getFirmwareVersion(std::string fwType, zes_firmwar
|
||||
// not able to read PSC version from iaf.x
|
||||
return result;
|
||||
}
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, pscVersion.c_str(), ZES_STRING_PROPERTY_SIZE);
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, pscVersion.c_str(), ZES_STRING_PROPERTY_SIZE - 1);
|
||||
return result;
|
||||
}
|
||||
ze_result_t result = pFwInterface->getFwVersion(fwType, fwVersion);
|
||||
if (result == ZE_RESULT_SUCCESS) {
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, fwVersion.c_str(), ZES_STRING_PROPERTY_SIZE);
|
||||
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, fwVersion.c_str(), ZES_STRING_PROPERTY_SIZE - 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
} // namespace L0
|
||||
|
||||
Reference in New Issue
Block a user