diff --git a/Dbg.c b/Dbg.c index 2d808b0e..71d5c71d 100644 --- a/Dbg.c +++ b/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; } diff --git a/commandlog.c b/commandlog.c index 1d33d77e..b253d79f 100644 --- a/commandlog.c +++ b/commandlog.c @@ -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 "); diff --git a/exebuf.c b/exebuf.c index 789f8687..0380a7df 100644 --- a/exebuf.c +++ b/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 */ diff --git a/exeman.c b/exeman.c index 83b6c284..73b6279a 100644 --- a/exeman.c +++ b/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; diff --git a/help.c b/help.c index 7b9e9d82..1164e095 100644 --- a/help.c +++ b/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; diff --git a/ifile.c b/ifile.c index c5cbdc34..a35fc862 100644 --- a/ifile.c +++ b/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); diff --git a/logreader.c b/logreader.c index cc6f8099..79cf8809 100644 --- a/logreader.c +++ b/logreader.c @@ -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; diff --git a/scan.c b/scan.c index 2abb4edb..0333aa48 100644 --- a/scan.c +++ b/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); } diff --git a/synchronize.c b/synchronize.c index 5a7d1a7a..1ca717e8 100644 --- a/synchronize.c +++ b/synchronize.c @@ -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) { diff --git a/tclmotdriv.c b/tclmotdriv.c index c774858c..c27639c6 100644 --- a/tclmotdriv.c +++ b/tclmotdriv.c @@ -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);