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개의 파일을 삭제
+2 -2
파일 보기
@@ -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();
+1 -1
파일 보기
@@ -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*) &macro);