- fixed some potential bugs introduced when replacing strncpy and

strncat by strlcpy and strlcat
This commit is contained in:
zolliker
2010-04-14 08:46:17 +00:00
parent 1c558e7f6c
commit 9690db1c3d
10 changed files with 20 additions and 20 deletions

4
Dbg.c
View File

@ -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;
}

View File

@ -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 ");

View File

@ -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 */

View File

@ -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
View File

@ -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;

View File

@ -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);

View File

@ -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
View File

@ -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);
}

View File

@ -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) {

View File

@ -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);