Use strncpy

Use strncpy instead of strcpy to ensure the arrays will not be
overflowered. Only copy one less than size of char array to leave a
NUL character at the end even if the copy is truncated provided the
original object is zeroed memory.

Change-Id: I00f7679630cf28dcb9a51cb0aba2810a4f4c72b9
这个提交包含在:
Tony Tye
2021-01-10 12:05:36 +00:00
父节点 76c371d78a
当前提交 e0448535a3
共修改 6 个文件,包含 24 行新增和 25 行删除
+5 -5
查看文件
@@ -496,11 +496,11 @@ void NullDevice::fillDeviceInfo(const CALdeviceattribs& calAttr, const gslMemInf
if ((calTarget() == CAL_TARGET_CARRIZO) && ASICREV_IS_CARRIZO_BRISTOL(calAttr.asicRevision)) {
const static char* bristol = "Bristol Ridge";
::strcpy(info_.name_, bristol);
::strncpy(info_.name_, bristol, sizeof(info_.name_) - 1);
} else {
::strcpy(info_.name_, hwInfo()->targetName_);
::strncpy(info_.name_, hwInfo()->targetName_, sizeof(info_.name_) - 1);
}
::strcpy(info_.vendor_, "Advanced Micro Devices, Inc.");
::strncpy(info_.vendor_, "Advanced Micro Devices, Inc.", sizeof(info_.vendor_) - 1);
::snprintf(info_.driverVersion_, sizeof(info_.driverVersion_) - 1, AMD_BUILD_STRING);
info_.profile_ = "FULL_PROFILE";
@@ -536,7 +536,7 @@ void NullDevice::fillDeviceInfo(const CALdeviceattribs& calAttr, const gslMemInf
info_.extensions_ = getExtensionString();
::strncpy(info_.driverStore_, calAttr.driverStore, sizeof(info_.driverStore_));
::strncpy(info_.driverStore_, calAttr.driverStore, sizeof(info_.driverStore_) - 1);
// OpenCL1.2 device info fields
info_.builtInKernels_ = "";
@@ -577,7 +577,7 @@ void NullDevice::fillDeviceInfo(const CALdeviceattribs& calAttr, const gslMemInf
}
if (settings().checkExtension(ClAmdDeviceAttributeQuery)) {
::strncpy(info_.boardName_, calAttr.boardName, sizeof(info_.boardName_));
::strncpy(info_.boardName_, calAttr.boardName, sizeof(info_.boardName_) - 1);
info_.deviceTopology_.pcie.type = CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD;
info_.deviceTopology_.pcie.bus = (calAttr.pciTopologyInformation & (0xFF << 8)) >> 8;