- After a bug at TRICS I replaced all occurrences of strcpy, strcat, sprintf

by length limited versions wherever appropriate.
This commit is contained in:
koennecke
2009-12-04 12:58:45 +00:00
parent 09826fb097
commit 4127cbb166
9 changed files with 42 additions and 43 deletions

View File

@ -17,7 +17,6 @@
#include <conman.h> #include <conman.h>
#include <servlog.h> #include <servlog.h>
#include <fortify.h> #include <fortify.h>
#include "evdriver.h" #include "evdriver.h"
#include "hardsup/el755_def.h" #include "hardsup/el755_def.h"
#include "hardsup/el755_errcodes.h" #include "hardsup/el755_errcodes.h"

View File

@ -89,13 +89,13 @@ int FocusAverageDo(SConnection * pCon, SicsInterp * pSics, void *pData,
} }
iRet = Tcl_GetInt(pSics->pTcl, argv[1], &iStart); iRet = Tcl_GetInt(pSics->pTcl, argv[1], &iStart);
if (iRet != TCL_OK) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iEnd); iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iEnd);
if (iRet != TCL_OK) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
@ -105,7 +105,7 @@ int FocusAverageDo(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc > 3) { if (argc > 3) {
iRet = Tcl_GetInt(pSics->pTcl, argv[3], &iBank); iRet = Tcl_GetInt(pSics->pTcl, argv[3], &iBank);
if (iRet != TCL_OK) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
@ -347,18 +347,18 @@ int MakeFA(SConnection * pCon, SicsInterp * pSics, void *pData,
/* find histogram memory */ /* find histogram memory */
pCom = FindCommand(pSics, argv[2]); pCom = FindCommand(pSics, argv[2]);
if (!pCom) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
pDum = (pDummy) pCom->pData; pDum = (pDummy) pCom->pData;
if (!pDum) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
if (strcmp(pDum->pDescriptor->name, "HMcontrol") != 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]); argv[2]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return 0; return 0;

View File

@ -118,13 +118,13 @@ static int readFileFrame(SConnection * pCon,
status = NXopen(file, NXACC_READ, &fileHandle); status = NXopen(file, NXACC_READ, &fileHandle);
if (status != NX_OK) { 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); SCWrite(pCon, error, eError);
return 0; return 0;
} }
status = NXDinitfromfile(dictFile, &dictHandle); status = NXDinitfromfile(dictFile, &dictHandle);
if (status != NX_OK) { 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); NXclose(&fileHandle);
SCWrite(pCon, error, eError); SCWrite(pCon, error, eError);
return 0; return 0;
@ -132,7 +132,7 @@ static int readFileFrame(SConnection * pCon,
status = NXDopenalias(fileHandle, dictHandle, alias); status = NXDopenalias(fileHandle, dictHandle, alias);
if (status != NX_OK) { 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); NXclose(&fileHandle);
NXDclose(dictHandle, NULL); NXDclose(dictHandle, NULL);
SCWrite(pCon, error, eError); SCWrite(pCon, error, eError);

View File

@ -120,7 +120,7 @@ static int countTokens(char *lineBuffer)
memset(myBuffer, 0, BUFLEN); memset(myBuffer, 0, BUFLEN);
strcpy(myBuffer, lineBuffer); strncpy(myBuffer, lineBuffer,BUFLEN);
pPtr = myBuffer; pPtr = myBuffer;
pPtr = stptok(pPtr, token, 60, " \r\n"); pPtr = stptok(pPtr, token, 60, " \r\n");
while (pPtr != NULL) { while (pPtr != NULL) {
@ -178,7 +178,7 @@ static int LMD200Callback(int handle, void *userData)
pEnd = strchr(pPtr,(int)'\r'); pEnd = strchr(pPtr,(int)'\r');
while(pEnd != NULL){ while(pEnd != NULL){
*pEnd = '\0'; *pEnd = '\0';
strcpy(priv->lineBuffer,pPtr); strncpy(priv->lineBuffer,pPtr,BUFLEN);
interpretLine(self,priv); interpretLine(self,priv);
ANETreadConsume(priv->asChannel,(pEnd - pPtr)+1); ANETreadConsume(priv->asChannel,(pEnd - pPtr)+1);
pPtr = ANETreadPtr(priv->asChannel,&length); pPtr = ANETreadPtr(priv->asChannel,&length);

View File

@ -255,7 +255,7 @@ static void PoldiStart(pPolterdi self, SConnection * pCon)
return; return;
} }
if (scancheck == 0) { if (scancheck == 0) {
sprintf(pBueffel, "Writing %s ......", self->pFile); snprintf(pBueffel,255, "Writing %s ......", self->pFile);
SCWrite(pCon, pBueffel, eLog); SCWrite(pCon, pBueffel, eLog);
} }
@ -483,7 +483,7 @@ static void PoldiUpdate(pPolterdi self, SConnection * pCon)
} }
if (scancheck == 0) { if (scancheck == 0) {
time(&zeit); time(&zeit);
sprintf(pBueffel, "Updating %s on %s ", self->pFile, snprintf(pBueffel,255, "Updating %s on %s ", self->pFile,
asctime(localtime(&zeit))); asctime(localtime(&zeit)));
SCWrite(pCon, pBueffel, eWarning); SCWrite(pCon, pBueffel, eWarning);
} }
@ -752,7 +752,7 @@ int PolterAction(SConnection * pCon, SicsInterp * pSics,
} }
return 1; return 1;
} else if (strcmp(argv[1], "getfile") == 0) { } 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); SCWrite(pCon, pBueffel, eValue);
return 1; return 1;
} else if (strcmp(argv[1], "interval") == 0) { } 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); iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iVal);
if (iRet != TCL_OK) { if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: cannot convert --> %s <-- to number ", snprintf(pBueffel,511, "ERROR: cannot convert --> %s <-- to number ",
argv[2]); argv[2]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return 0; return 0;

24
psi.c
View File

@ -225,7 +225,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[])
/* create the motor */ /* create the motor */
pNew = MotorInit("PIPIEZO", argv[0], pDriver); pNew = MotorInit("PIPIEZO", argv[0], pDriver);
if (!pNew) { 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); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
@ -237,7 +237,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[])
/* create the motor */ /* create the motor */
pNew = MotorInit("EL734", argv[0], pDriver); pNew = MotorInit("EL734", argv[0], pDriver);
if (!pNew) { 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); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
@ -249,7 +249,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[])
/* create the motor */ /* create the motor */
pNew = MotorInit("EL734HP", argv[0], pDriver); pNew = MotorInit("EL734HP", argv[0], pDriver);
if (!pNew) { 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); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
@ -261,7 +261,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[])
/* create the motor */ /* create the motor */
pNew = MotorInit("EL734HPT", argv[0], pDriver); pNew = MotorInit("EL734HPT", argv[0], pDriver);
if (!pNew) { 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); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
@ -273,7 +273,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[])
/* create the motor */ /* create the motor */
pNew = MotorInit("EL734DC", argv[0], pDriver); pNew = MotorInit("EL734DC", argv[0], pDriver);
if (!pNew) { 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); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
@ -285,7 +285,7 @@ static pMotor CreatePsiMotor(SConnection * pCon, int argc, char *argv[])
/* create the motor */ /* create the motor */
pNew = MotorInit("ECB", argv[0], pDriver); pNew = MotorInit("ECB", argv[0], pDriver);
if (!pNew) { 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); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
@ -389,14 +389,14 @@ static pCodri CreatePsiController(SConnection * pCon, int argc,
} }
iRet = Tcl_GetInt(pTcl, argv[2], &iPort); iRet = Tcl_GetInt(pTcl, argv[2], &iPort);
if (iRet != TCL_OK) { 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]); argv[2]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
} }
iRet = Tcl_GetInt(pTcl, argv[3], &iChannel); iRet = Tcl_GetInt(pTcl, argv[3], &iChannel);
if (iRet != TCL_OK) { if (iRet != TCL_OK) {
sprintf(pBueffel, snprintf(pBueffel,511,
"ERROR: expected integer as channel number, got %s", "ERROR: expected integer as channel number, got %s",
argv[3]); argv[3]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
@ -405,7 +405,7 @@ static pCodri CreatePsiController(SConnection * pCon, int argc,
if (argc > 4) { if (argc > 4) {
iRet = Tcl_GetInt(pTcl, argv[4], &iSingle); iRet = Tcl_GetInt(pTcl, argv[4], &iSingle);
if (iRet != TCL_OK) { if (iRet != TCL_OK) {
sprintf(pBueffel, snprintf(pBueffel,511,
"ERROR: expected integer as single flag, got %s", argv[4]); "ERROR: expected integer as single flag, got %s", argv[4]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
@ -429,7 +429,7 @@ static pCodri CreatePsiController(SConnection * pCon, int argc,
} }
iRet = Tcl_GetInt(pTcl, argv[2], &iPort); iRet = Tcl_GetInt(pTcl, argv[2], &iPort);
if (iRet != TCL_OK) { 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]); argv[2]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
@ -576,7 +576,7 @@ static pEVControl InstallPsiEnvironmentController(SicsInterp * pSics,
pNew = CreateEVController(pDriv, argv[2], &status); pNew = CreateEVController(pDriv, argv[2], &status);
} }
} else { } 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]); argv[3]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return NULL; return NULL;
@ -591,7 +591,7 @@ static pEVControl InstallPsiEnvironmentController(SicsInterp * pSics,
if (status != 1) { if (status != 1) {
SCWrite(pCon, "ERROR: failed to initialize device", eError); SCWrite(pCon, "ERROR: failed to initialize device", eError);
pDriv->GetError(pDriv, &status, pError, 131); pDriv->GetError(pDriv, &status, pError, 131);
sprintf(pBueffel, "HW reported: %s", pError); snprintf(pBueffel, 511,"HW reported: %s", pError);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
} }
if (pNew == NULL) { if (pNew == NULL) {

View File

@ -275,14 +275,14 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData,
/* the last arument must denote a velocity selector */ /* the last arument must denote a velocity selector */
pCom = FindCommand(pSics, argv[2]); pCom = FindCommand(pSics, argv[2]);
if (!pCom) { 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); SCWrite(pCon, pBueffel, eError);
KillSANSWave(pNew); KillSANSWave(pNew);
return 0; return 0;
} }
pNew->pSelector = pCom->pData; pNew->pSelector = pCom->pData;
if (!pNew->pSelector) { 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); SCWrite(pCon, pBueffel, eError);
KillSANSWave(pNew); KillSANSWave(pNew);
return 0; return 0;
@ -290,7 +290,7 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData,
pDum = (pDummy) pNew->pSelector; pDum = (pDummy) pNew->pSelector;
if (strcmp(pDum->pDescriptor->name, "VelocitySelector") != 0 if (strcmp(pDum->pDescriptor->name, "VelocitySelector") != 0
&& strcmp(pDum->pDescriptor->name,"NVS") != 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); SCWrite(pCon, pBueffel, eError);
KillSANSWave(pNew); KillSANSWave(pNew);
return 0; return 0;
@ -315,7 +315,7 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData,
/* install command */ /* install command */
iRet = AddCommand(pSics, argv[1], SANSWaveAction, KillSANSWave, pNew); iRet = AddCommand(pSics, argv[1], SANSWaveAction, KillSANSWave, pNew);
if (!iRet) { 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); SCWrite(pCon, pBueffel, eError);
KillSANSWave(pNew); KillSANSWave(pNew);
return 0; return 0;
@ -349,7 +349,7 @@ int SANSWaveAction(SConnection * pCon, SicsInterp * pSics, void *pData,
/* the second argument must be a number */ /* the second argument must be a number */
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dNum); iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dNum);
if (iRet != TCL_OK) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
@ -365,7 +365,7 @@ int SANSWaveAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCWrite(pCon, pBueffel, eValue); SCWrite(pCon, pBueffel, eValue);
return 1; return 1;
} else { } else {
sprintf(pBueffel, "ERROR: subcommand %s NOT understood", argv[1]); snprintf(pBueffel,255, "ERROR: subcommand %s NOT understood", argv[1]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }

View File

@ -60,7 +60,7 @@ static void PrintHMError(char *text, SConnection * pCon)
char pBueffel[1064]; char pBueffel[1064];
strcpy(pBueffel, "ERROR: Histogram Memory --> "); strcpy(pBueffel, "ERROR: Histogram Memory --> ");
strcat(pBueffel, text); strncat(pBueffel, text,1024);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
} }
@ -160,7 +160,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon,
strtolower(pValue); strtolower(pValue);
iRet = Text2Mode(pValue); iRet = Text2Mode(pValue);
if (iRet < 0) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
@ -175,7 +175,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon,
strtolower(pValue); strtolower(pValue);
iRet = Text2Flow(pValue); iRet = Text2Flow(pValue);
if (iRet < 0) { if (iRet < 0) {
sprintf(pBueffel, "ERROR: Invalid parameter %s to OverflowMode", snprintf(pBueffel,255, "ERROR: Invalid parameter %s to OverflowMode",
pValue); pValue);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
@ -187,7 +187,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon,
if (!iRet) { if (!iRet) {
iRet = StringDictGet(pOpt, "binwidth", pValue, 79); iRet = StringDictGet(pOpt, "binwidth", pValue, 79);
if (iRet) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} else { } else {
@ -196,7 +196,7 @@ static int SQConfigure(pHistDriver self, SConnection * pCon,
} }
} }
if (fVal < 1) { 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); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }

View File

@ -1,9 +1,9 @@
/* /*
* This is yet another protocol for scriptcontext. This is for variable * This is yet another protocol for scriptcontext. This is for variable
* terminated protocols. The Astriums have deliverd the SANS-2 NVS with * terminated protocols. The Astriums have delivered the SANS-2 NVS with
* a protocol which uses a \n as a terminator most of teh time but sometimes * a protocol which uses a \n as a terminator most of the time but sometimes
* a \. This protocl handler expects messages in the form: terminator:payload * a \. This protocol handler expects messages in the form: terminator:payload
* The caller is responsible for providing the proper send termiantor. * The caller is responsible for providing the proper send terminator.
* *
* copyright: see file COPYRIGHT * copyright: see file COPYRIGHT
* *