- fixed some potential bugs introduced when replacing strncpy and
strncat by strlcpy and strlcat
This commit is contained in:
4
Dbg.c
4
Dbg.c
@ -410,7 +410,7 @@ char *argv[];
|
||||
if (compress) {
|
||||
/* this copies from our static buf to printify's static buf */
|
||||
/* and back to our static buf */
|
||||
strlcpy(buf, printify(buf), buf_width);
|
||||
strncpy(buf, printify(buf), buf_width);
|
||||
}
|
||||
|
||||
/* usually but not always right, but assume truncation if buffer is */
|
||||
@ -684,7 +684,7 @@ char **argv;
|
||||
|
||||
if (argc == 1)
|
||||
argv[1] = "1";
|
||||
strlcpy(viewFrameName, argv[1], FRAMENAMELEN);
|
||||
strncpy(viewFrameName, argv[1], FRAMENAMELEN);
|
||||
|
||||
return TCL_RETURN;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ void WriteToCommandLogId(char *prompt, int id, char *text)
|
||||
pCopy = malloc(l + 1);
|
||||
if (pCopy == NULL)
|
||||
return;
|
||||
strlcpy(pCopy, text, l);
|
||||
strncpy(pCopy, text, l); /* strlcpy is not correct here */
|
||||
pCopy[l] = '\0';
|
||||
if (prompt == cmdPrompt && iCompact) {
|
||||
pPtr = strstr(pCopy, "fulltransact ");
|
||||
|
2
exebuf.c
2
exebuf.c
@ -210,7 +210,7 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics,
|
||||
}
|
||||
l = ende - cmd;
|
||||
if (l < sizeof cmdName) {
|
||||
strlcpy(cmdName, cmd, l);
|
||||
strncpy(cmdName, cmd, l);
|
||||
cmdName[l] = '\0';
|
||||
if (FindCommand(pSics, cmdName) != NULL) {
|
||||
/* print only SICS commands */
|
||||
|
8
exeman.c
8
exeman.c
@ -201,15 +201,15 @@ static int makeExePath(pExeMan self, SConnection * pCon, int argc,
|
||||
* do nothing to absolute path
|
||||
*/
|
||||
if (argv[2][0] == '/') {
|
||||
strlcat(buffer, argv[2], 511 - strlen(buffer));
|
||||
strlcat(buffer, argv[2], sizeof buffer);
|
||||
SCWrite(pCon, buffer, eValue);
|
||||
return 1;
|
||||
}
|
||||
pPtr = self->batchPath;
|
||||
pPtr = stptok(pPtr, pPath, 131, ":");
|
||||
strlcat(buffer, pPath, 511 - strlen(buffer));
|
||||
strlcat(buffer, "/", 511 - strlen(buffer));
|
||||
strlcat(buffer, argv[2], 511 - strlen(buffer));
|
||||
strlcat(buffer, pPath, sizeof buffer);
|
||||
strlcat(buffer, "/", sizeof buffer);
|
||||
strlcat(buffer, argv[2], sizeof buffer);
|
||||
SCWrite(pCon, buffer, eValue);
|
||||
|
||||
return 1;
|
||||
|
6
help.c
6
help.c
@ -43,9 +43,9 @@ static FILE *findHelpFile(char *name)
|
||||
|
||||
pPtr = helpDirs;
|
||||
while ((pPtr = stptok(pPtr, dir, 131, PATHSEP)) != NULL) {
|
||||
strcpy(pBueffel, dir);
|
||||
strcat(pBueffel, DIRSEP);
|
||||
strlcat(pBueffel, name, (254 - strlen(pBueffel)));
|
||||
strlcpy(pBueffel, dir, sizeof pBueffel);
|
||||
strlcat(pBueffel, DIRSEP, sizeof pBueffel);
|
||||
strlcat(pBueffel, name, sizeof pBueffel);
|
||||
fd = fopen(pBueffel, "r");
|
||||
if (fd != NULL) {
|
||||
return fd;
|
||||
|
2
ifile.c
2
ifile.c
@ -118,7 +118,7 @@ IPair *IFReadConfigFile(FILE * fd)
|
||||
continue;
|
||||
|
||||
iLen = pPos - pBueffel;
|
||||
strlcpy(pName, pBueffel, iLen);
|
||||
strncpy(pName, pBueffel, iLen);
|
||||
pName[iLen] = '\0';
|
||||
strlcpy(pValue, (pPos + 1),131);
|
||||
RemoveWhiteSpace(pName);
|
||||
|
@ -502,7 +502,7 @@ static int LogReader(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
if (!inRange) {
|
||||
if (t < startim) {
|
||||
lastval[0] = '\0';
|
||||
strlcat(lastval, val, sizeof lastval - 1);
|
||||
strncat(lastval, val, sizeof lastval - 1);
|
||||
lastt = t;
|
||||
} else {
|
||||
inRange = 1;
|
||||
|
8
scan.c
8
scan.c
@ -1396,16 +1396,16 @@ static void PrintScanVars(pScanData self, char *scanname,
|
||||
assert(pCon);
|
||||
assert(self);
|
||||
|
||||
snprintf(pBueffel, 1023, "%s.scanvars = { ", scanname);
|
||||
snprintf(pBueffel, sizeof pBueffel, "%s.scanvars = { ", scanname);
|
||||
for (i = 0; i < self->iScanVar; i++) {
|
||||
DynarGet(self->pScanVar, i, &pPtr);
|
||||
pVar = (pVarEntry) pPtr;
|
||||
if (pVar != NULL) {
|
||||
strlcat(pBueffel, ScanVarName(pVar), 1023 - strlen(pBueffel));
|
||||
strcat(pBueffel, " ");
|
||||
strlcat(pBueffel, ScanVarName(pVar), sizeof pBueffel);
|
||||
strlcat(pBueffel, " ", sizeof pBueffel);
|
||||
}
|
||||
}
|
||||
strcat(pBueffel, "}");
|
||||
strlcat(pBueffel, "}", sizeof pBueffel);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ tryagain:
|
||||
return 0;
|
||||
} else {
|
||||
if (test > 0) {
|
||||
strlcat(pBueffel, pRead, 2047 - strlen(pBueffel));
|
||||
strlcat(pBueffel, pRead, sizeof pBueffel);
|
||||
}
|
||||
}
|
||||
if (strstr(pBueffel, "TRANSACTIONFINISHED") != NULL) {
|
||||
|
@ -99,7 +99,7 @@ static int TclRun(void *self, float fVal)
|
||||
return HWFault;
|
||||
}
|
||||
snprintf(num, 79, "%f", fVal);
|
||||
strlcat(tclCommand, num, 1023 - strlen(tclCommand));
|
||||
strlcat(tclCommand, num, sizeof tclCommand);
|
||||
|
||||
status = Tcl_Eval(pServ->pSics->pTcl, tclCommand);
|
||||
result = Tcl_GetStringResult(pServ->pSics->pTcl);
|
||||
@ -199,7 +199,7 @@ static int TclFix(void *self, int iError, float fNew)
|
||||
return HWFault;
|
||||
}
|
||||
snprintf(num, 79, "%d %f", pDriv->errorCode, fNew);
|
||||
strlcat(tclCommand, num, 1023 - strlen(tclCommand));
|
||||
strlcat(tclCommand, num, sizeof tclCommand);
|
||||
|
||||
status = Tcl_Eval(pServ->pSics->pTcl, tclCommand);
|
||||
result = Tcl_GetStringResult(pServ->pSics->pTcl);
|
||||
|
Reference in New Issue
Block a user