From 4127cbb166ffa7aa6bf255a0f1f0fe5064c431bd Mon Sep 17 00:00:00 2001 From: koennecke Date: Fri, 4 Dec 2009 12:58:45 +0000 Subject: [PATCH] - After a bug at TRICS I replaced all occurrences of strcpy, strcat, sprintf by length limited versions wherever appropriate. --- el755driv.c | 1 - faverage.c | 12 ++++++------ frame.c | 6 +++--- lmd200.c | 4 ++-- polterwrite.c | 8 ++++---- psi.c | 24 ++++++++++++------------ sanswave.c | 12 ++++++------ sinqhmdriv.c | 10 +++++----- termprot.c | 8 ++++---- 9 files changed, 42 insertions(+), 43 deletions(-) diff --git a/el755driv.c b/el755driv.c index 08a15db..7172459 100644 --- a/el755driv.c +++ b/el755driv.c @@ -17,7 +17,6 @@ #include #include #include - #include "evdriver.h" #include "hardsup/el755_def.h" #include "hardsup/el755_errcodes.h" diff --git a/faverage.c b/faverage.c index 7620d75..070f76c 100644 --- a/faverage.c +++ b/faverage.c @@ -89,13 +89,13 @@ int FocusAverageDo(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetInt(pSics->pTcl, argv[1], &iStart); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: cannot convert %s to integer", argv[1]); + snprintf(pBueffel,255, "ERROR: cannot convert %s to integer", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iEnd); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: cannot convert %s to integer", argv[2]); + snprintf(pBueffel,255, "ERROR: cannot convert %s to integer", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -105,7 +105,7 @@ int FocusAverageDo(SConnection * pCon, SicsInterp * pSics, void *pData, if (argc > 3) { iRet = Tcl_GetInt(pSics->pTcl, argv[3], &iBank); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: cannot convert %s to integer", argv[3]); + snprintf(pBueffel,255, "ERROR: cannot convert %s to integer", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -347,18 +347,18 @@ int MakeFA(SConnection * pCon, SicsInterp * pSics, void *pData, /* find histogram memory */ pCom = FindCommand(pSics, argv[2]); if (!pCom) { - sprintf(pBueffel, "ERROR: histogram memory %s NOT found!", argv[2]); + snprintf(pBueffel,255, "ERROR: histogram memory %s NOT found!", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } pDum = (pDummy) pCom->pData; if (!pDum) { - sprintf(pBueffel, "ERROR: histogram memory %s INVALID!", argv[2]); + snprintf(pBueffel,255, "ERROR: histogram memory %s INVALID!", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } if (strcmp(pDum->pDescriptor->name, "HMcontrol") != 0) { - sprintf(pBueffel, "ERROR: %s is NO histogram control object!", + snprintf(pBueffel,255, "ERROR: %s is NO histogram control object!", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/frame.c b/frame.c index 055c6fa..5580d48 100644 --- a/frame.c +++ b/frame.c @@ -118,13 +118,13 @@ static int readFileFrame(SConnection * pCon, status = NXopen(file, NXACC_READ, &fileHandle); if (status != NX_OK) { - sprintf(error, "ERROR: failed to open %s", file); + snprintf(error,511, "ERROR: failed to open %s", file); SCWrite(pCon, error, eError); return 0; } status = NXDinitfromfile(dictFile, &dictHandle); if (status != NX_OK) { - sprintf(error, "ERROR: failed to open dictionary %s", dictFile); + snprintf(error,511, "ERROR: failed to open dictionary %s", dictFile); NXclose(&fileHandle); SCWrite(pCon, error, eError); return 0; @@ -132,7 +132,7 @@ static int readFileFrame(SConnection * pCon, status = NXDopenalias(fileHandle, dictHandle, alias); if (status != NX_OK) { - sprintf(error, "ERROR: failed to open alias %s", alias); + snprintf(error,511, "ERROR: failed to open alias %s", alias); NXclose(&fileHandle); NXDclose(dictHandle, NULL); SCWrite(pCon, error, eError); diff --git a/lmd200.c b/lmd200.c index 2c9279b..c038d68 100644 --- a/lmd200.c +++ b/lmd200.c @@ -120,7 +120,7 @@ static int countTokens(char *lineBuffer) memset(myBuffer, 0, BUFLEN); - strcpy(myBuffer, lineBuffer); + strncpy(myBuffer, lineBuffer,BUFLEN); pPtr = myBuffer; pPtr = stptok(pPtr, token, 60, " \r\n"); while (pPtr != NULL) { @@ -178,7 +178,7 @@ static int LMD200Callback(int handle, void *userData) pEnd = strchr(pPtr,(int)'\r'); while(pEnd != NULL){ *pEnd = '\0'; - strcpy(priv->lineBuffer,pPtr); + strncpy(priv->lineBuffer,pPtr,BUFLEN); interpretLine(self,priv); ANETreadConsume(priv->asChannel,(pEnd - pPtr)+1); pPtr = ANETreadPtr(priv->asChannel,&length); diff --git a/polterwrite.c b/polterwrite.c index 37ee938..4859fc6 100644 --- a/polterwrite.c +++ b/polterwrite.c @@ -255,7 +255,7 @@ static void PoldiStart(pPolterdi self, SConnection * pCon) return; } if (scancheck == 0) { - sprintf(pBueffel, "Writing %s ......", self->pFile); + snprintf(pBueffel,255, "Writing %s ......", self->pFile); SCWrite(pCon, pBueffel, eLog); } @@ -483,7 +483,7 @@ static void PoldiUpdate(pPolterdi self, SConnection * pCon) } if (scancheck == 0) { time(&zeit); - sprintf(pBueffel, "Updating %s on %s ", self->pFile, + snprintf(pBueffel,255, "Updating %s on %s ", self->pFile, asctime(localtime(&zeit))); SCWrite(pCon, pBueffel, eWarning); } @@ -752,7 +752,7 @@ int PolterAction(SConnection * pCon, SicsInterp * pSics, } return 1; } else if (strcmp(argv[1], "getfile") == 0) { - sprintf(pBueffel, "StoreData.file = %s", self->pFile); + snprintf(pBueffel,511, "StoreData.file = %s", self->pFile); SCWrite(pCon, pBueffel, eValue); return 1; } else if (strcmp(argv[1], "interval") == 0) { @@ -762,7 +762,7 @@ int PolterAction(SConnection * pCon, SicsInterp * pSics, } iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: cannot convert --> %s <-- to number ", + snprintf(pBueffel,511, "ERROR: cannot convert --> %s <-- to number ", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/psi.c b/psi.c index aaf1bf1..6d4d97f 100644 --- a/psi.c +++ b/psi.c @@ -225,7 +225,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[]) /* create the motor */ pNew = MotorInit("PIPIEZO", argv[0], pDriver); if (!pNew) { - sprintf(pBueffel, "Failure to create motor %s", argv[0]); + snprintf(pBueffel,131, "Failure to create motor %s", argv[0]); SCWrite(pCon, pBueffel, eError); return NULL; } @@ -237,7 +237,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[]) /* create the motor */ pNew = MotorInit("EL734", argv[0], pDriver); if (!pNew) { - sprintf(pBueffel, "Failure to create motor %s", argv[1]); + snprintf(pBueffel,131, "Failure to create motor %s", argv[1]); SCWrite(pCon, pBueffel, eError); return NULL; } @@ -249,7 +249,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[]) /* create the motor */ pNew = MotorInit("EL734HP", argv[0], pDriver); if (!pNew) { - sprintf(pBueffel, "Failure to create motor %s", argv[1]); + snprintf(pBueffel,131, "Failure to create motor %s", argv[1]); SCWrite(pCon, pBueffel, eError); return NULL; } @@ -261,7 +261,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[]) /* create the motor */ pNew = MotorInit("EL734HPT", argv[0], pDriver); if (!pNew) { - sprintf(pBueffel, "Failure to create motor %s", argv[1]); + snprintf(pBueffel,131, "Failure to create motor %s", argv[1]); SCWrite(pCon, pBueffel, eError); return NULL; } @@ -273,7 +273,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[]) /* create the motor */ pNew = MotorInit("EL734DC", argv[0], pDriver); if (!pNew) { - sprintf(pBueffel, "Failure to create motor %s", argv[1]); + snprintf(pBueffel,131, "Failure to create motor %s", argv[1]); SCWrite(pCon, pBueffel, eError); return NULL; } @@ -285,7 +285,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[]) /* create the motor */ pNew = MotorInit("ECB", argv[0], pDriver); if (!pNew) { - sprintf(pBueffel, "Failure to create motor %s", argv[0]); + snprintf(pBueffel,131, "Failure to create motor %s", argv[0]); SCWrite(pCon, pBueffel, eError); return NULL; } @@ -389,14 +389,14 @@ static pCodri CreatePsiController(SConnection * pCon, int argc, } iRet = Tcl_GetInt(pTcl, argv[2], &iPort); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: expected integer as port number, got %s", + snprintf(pBueffel,511, "ERROR: expected integer as port number, got %s", argv[2]); SCWrite(pCon, pBueffel, eError); return NULL; } iRet = Tcl_GetInt(pTcl, argv[3], &iChannel); if (iRet != TCL_OK) { - sprintf(pBueffel, + snprintf(pBueffel,511, "ERROR: expected integer as channel number, got %s", argv[3]); SCWrite(pCon, pBueffel, eError); @@ -405,7 +405,7 @@ static pCodri CreatePsiController(SConnection * pCon, int argc, if (argc > 4) { iRet = Tcl_GetInt(pTcl, argv[4], &iSingle); if (iRet != TCL_OK) { - sprintf(pBueffel, + snprintf(pBueffel,511, "ERROR: expected integer as single flag, got %s", argv[4]); SCWrite(pCon, pBueffel, eError); return NULL; @@ -429,7 +429,7 @@ static pCodri CreatePsiController(SConnection * pCon, int argc, } iRet = Tcl_GetInt(pTcl, argv[2], &iPort); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: expected integer as port number, got %s", + snprintf(pBueffel, 511, "ERROR: expected integer as port number, got %s", argv[2]); SCWrite(pCon, pBueffel, eError); return NULL; @@ -576,7 +576,7 @@ static pEVControl InstallPsiEnvironmentController(SicsInterp * pSics, pNew = CreateEVController(pDriv, argv[2], &status); } } else { - sprintf(pBueffel, "ERROR: %s not recognized as a valid driver type", + snprintf(pBueffel,511, "ERROR: %s not recognized as a valid driver type", argv[3]); SCWrite(pCon, pBueffel, eError); return NULL; @@ -591,7 +591,7 @@ static pEVControl InstallPsiEnvironmentController(SicsInterp * pSics, if (status != 1) { SCWrite(pCon, "ERROR: failed to initialize device", eError); pDriv->GetError(pDriv, &status, pError, 131); - sprintf(pBueffel, "HW reported: %s", pError); + snprintf(pBueffel, 511,"HW reported: %s", pError); SCWrite(pCon, pBueffel, eError); } if (pNew == NULL) { diff --git a/sanswave.c b/sanswave.c index e3e382d..8f21efb 100644 --- a/sanswave.c +++ b/sanswave.c @@ -275,14 +275,14 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData, /* the last arument must denote a velocity selector */ pCom = FindCommand(pSics, argv[2]); if (!pCom) { - sprintf(pBueffel, "ERROR: velocity selector %s NOT found", argv[2]); + snprintf(pBueffel,511, "ERROR: velocity selector %s NOT found", argv[2]); SCWrite(pCon, pBueffel, eError); KillSANSWave(pNew); return 0; } pNew->pSelector = pCom->pData; if (!pNew->pSelector) { - sprintf(pBueffel, "ERROR: velocity selector %s is invalid", argv[2]); + snprintf(pBueffel,511, "ERROR: velocity selector %s is invalid", argv[2]); SCWrite(pCon, pBueffel, eError); KillSANSWave(pNew); return 0; @@ -290,7 +290,7 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData, pDum = (pDummy) pNew->pSelector; if (strcmp(pDum->pDescriptor->name, "VelocitySelector") != 0 && strcmp(pDum->pDescriptor->name,"NVS") != 0) { - sprintf(pBueffel, "ERROR: velocity selector %s is invalid", argv[2]); + snprintf(pBueffel,511, "ERROR: velocity selector %s is invalid", argv[2]); SCWrite(pCon, pBueffel, eError); KillSANSWave(pNew); return 0; @@ -315,7 +315,7 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData, /* install command */ iRet = AddCommand(pSics, argv[1], SANSWaveAction, KillSANSWave, pNew); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s NOT created", argv[1]); + snprintf(pBueffel,511, "ERROR: duplicate command %s NOT created", argv[1]); SCWrite(pCon, pBueffel, eError); KillSANSWave(pNew); return 0; @@ -349,7 +349,7 @@ int SANSWaveAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* the second argument must be a number */ iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dNum); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: cannot convert %s to number", argv[2]); + snprintf(pBueffel,255, "ERROR: cannot convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -365,7 +365,7 @@ int SANSWaveAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, pBueffel, eValue); return 1; } else { - sprintf(pBueffel, "ERROR: subcommand %s NOT understood", argv[1]); + snprintf(pBueffel,255, "ERROR: subcommand %s NOT understood", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/sinqhmdriv.c b/sinqhmdriv.c index f0ce9ee..cbb7123 100644 --- a/sinqhmdriv.c +++ b/sinqhmdriv.c @@ -60,7 +60,7 @@ static void PrintHMError(char *text, SConnection * pCon) char pBueffel[1064]; strcpy(pBueffel, "ERROR: Histogram Memory --> "); - strcat(pBueffel, text); + strncat(pBueffel, text,1024); SCWrite(pCon, pBueffel, eError); } @@ -160,7 +160,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon, strtolower(pValue); iRet = Text2Mode(pValue); if (iRet < 0) { - sprintf(pBueffel, "ERROR: Invalid parameter %s to HistMode", pValue); + snprintf(pBueffel,255, "ERROR: Invalid parameter %s to HistMode", pValue); SCWrite(pCon, pBueffel, eError); return 0; } @@ -175,7 +175,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon, strtolower(pValue); iRet = Text2Flow(pValue); if (iRet < 0) { - sprintf(pBueffel, "ERROR: Invalid parameter %s to OverflowMode", + snprintf(pBueffel,255, "ERROR: Invalid parameter %s to OverflowMode", pValue); SCWrite(pCon, pBueffel, eError); return 0; @@ -187,7 +187,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon, if (!iRet) { iRet = StringDictGet(pOpt, "binwidth", pValue, 79); if (iRet) { - sprintf(pBueffel, "ERROR: %s not valid for BinWidth ", pValue); + snprintf(pBueffel,255, "ERROR: %s not valid for BinWidth ", pValue); SCWrite(pCon, pBueffel, eError); return 0; } else { @@ -196,7 +196,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon, } } if (fVal < 1) { - sprintf(pBueffel, "ERROR: %f is invalid for BinWidth", fVal); + snprintf(pBueffel,255, "ERROR: %f is invalid for BinWidth", fVal); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/termprot.c b/termprot.c index 7d4821f..b51d486 100644 --- a/termprot.c +++ b/termprot.c @@ -1,9 +1,9 @@ /* * This is yet another protocol for scriptcontext. This is for variable - * terminated protocols. The Astriums have deliverd the SANS-2 NVS with - * a protocol which uses a \n as a terminator most of teh time but sometimes - * a \. This protocl handler expects messages in the form: terminator:payload - * The caller is responsible for providing the proper send termiantor. + * terminated protocols. The Astriums have delivered the SANS-2 NVS with + * a protocol which uses a \n as a terminator most of the time but sometimes + * a \. This protocol handler expects messages in the form: terminator:payload + * The caller is responsible for providing the proper send terminator. * * copyright: see file COPYRIGHT *