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
This commit is contained in:
1 parent
76c371d78a
commit
e0448535a3
6 files changed
+24
-25
No files matched your search
@@ -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;
|
||||
|
||||
@@ -143,10 +143,10 @@ CALGSLDevice::getAttribs_int(gsl::gsCtx* cs)
|
||||
m_attribs.pciTopologyInformation = m_adp->getLocationId();
|
||||
|
||||
const uint8* boardName = cs->getString(GSL_GS_RENDERER);
|
||||
::strncpy(m_attribs.boardName, (char*)boardName, CAL_ASIC_INFO_MAX_LEN * sizeof(char));
|
||||
::strncpy(m_attribs.boardName, (char*)boardName, CAL_ASIC_INFO_MAX_LEN * sizeof(char) - 1);
|
||||
|
||||
const uint8* driverStore = cs->getString(GSL_GS_DRIVER_STORE_PATH);
|
||||
::strncpy(m_attribs.driverStore, (char*)driverStore, CAL_DRIVER_STORE_MAX_LEN * sizeof(char));
|
||||
::strncpy(m_attribs.driverStore, (char*)driverStore, CAL_DRIVER_STORE_MAX_LEN * sizeof(char) - 1);
|
||||
|
||||
m_attribs.counterFreq = cs->getCounterFreq();
|
||||
m_attribs.nanoSecondsPerTick = 1000000000.0 / cs->getCounterFreq();
|
||||
|
||||
@@ -62,7 +62,7 @@ getConfigFromFile(gslStaticRuntimeConfig& scfg,
|
||||
// Check if location string is longer than 128 then assign, if not default location will be C:\packet.txt in gsl_ctx.cpp: gsCtxManager::PacketDump()
|
||||
uintp length = commandbufferDumpFilename.length();
|
||||
if (length > 0 && length < sizeof(dcfg.CommandbufferDumpFilename))
|
||||
strcpy(dcfg.CommandbufferDumpFilename, commandbufferDumpFilename.c_str());
|
||||
::strncpy(dcfg.CommandbufferDumpFilename, commandbufferDumpFilename.c_str(), sizeof(dcfg.CommandbufferDumpFilename) - 1);
|
||||
|
||||
iniFile.getValue(section, CAL_ENABLEPATCHDUMP, (CALint*) &dcfg.nPatchDumpLevel.value);
|
||||
iniFile.getValue(section, CAL_ENABLEMACROTILE, (CALboolean*) ¯o);
|
||||
|
||||
Reference in new issue
Block a user