- After a bug at TRICS I replaced all occurrences of strcpy, strcat, sprintf
by length limited versions wherever appropriate. SKIPPED: psi/el755driv.c psi/faverage.c psi/frame.c psi/lmd200.c psi/polterwrite.c psi/psi.c psi/sanswave.c psi/sinqhmdriv.c psi/termprot.c
This commit is contained in:
95
SCinter.c
95
SCinter.c
@ -120,7 +120,7 @@ int AddCommandWithFlag(SicsInterp * pInterp, char *pName, ObjectFunc pFunc,
|
||||
assert(pFunc);
|
||||
assert(pInterp);
|
||||
|
||||
strcpy(pBueffel, pName);
|
||||
strncpy(pBueffel, pName,511);
|
||||
strtolower(pBueffel);
|
||||
RemoveAlias(&pInterp->AList, pBueffel); /* M.Z. */
|
||||
if (FindCommand(pInterp, pBueffel) != NULL) {
|
||||
@ -130,7 +130,7 @@ int AddCommandWithFlag(SicsInterp * pInterp, char *pName, ObjectFunc pFunc,
|
||||
/* new memory */
|
||||
pNew = (CommandList *) malloc(sizeof(CommandList));
|
||||
if (!pNew) {
|
||||
sprintf(pBueffel, "Out of memory creating command - %s -", pName);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Out of memory creating command - %s -", pName);
|
||||
SICSLogWrite(pBueffel, eInternal);
|
||||
return 0;
|
||||
}
|
||||
@ -198,7 +198,7 @@ int RemoveCommand(SicsInterp * pInterp, char *pName)
|
||||
assert(pInterp);
|
||||
assert(pName);
|
||||
|
||||
strcpy(pBueffel, pName);
|
||||
strncpy(pBueffel, pName,255);
|
||||
strtolower(pBueffel);
|
||||
|
||||
if (pInterp->iDeleting) {
|
||||
@ -263,11 +263,11 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText)
|
||||
|
||||
/* write info to Log */
|
||||
if (pCon->sockHandle >= 0) {
|
||||
sprintf(pBueffel, "Executing -> %s <- from socket %d", pText,
|
||||
snprintf(pBueffel,1023, "Executing -> %s <- from socket %d", pText,
|
||||
pCon->sockHandle);
|
||||
SICSLogWrite(pBueffel, eCommand);
|
||||
} else {
|
||||
sprintf(pBueffel, "Executing -> %s <- from dummy socket\n", pText);
|
||||
snprintf(pBueffel,1023, "Executing -> %s <- from dummy socket\n", pText);
|
||||
SICSLogWrite(pBueffel, eCommand);
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText)
|
||||
/* find it */
|
||||
pCommand = FindCommand(self, argv[0]);
|
||||
if (!pCommand) {
|
||||
sprintf(pBueffel, "ERROR: Object -> %s <- NOT found", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Object -> %s <- NOT found", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
iRet = -1;
|
||||
goto deleteArgv;
|
||||
@ -333,7 +333,7 @@ deleteArgv:
|
||||
CommandList *FindCommand(SicsInterp * self, char *pName)
|
||||
{
|
||||
CommandList *pCurrent = NULL;
|
||||
char pBueffel[256], *pCmd;
|
||||
char pBuffer[1024], *pCmd, *pBueffel = NULL;
|
||||
|
||||
assert(self);
|
||||
|
||||
@ -341,7 +341,18 @@ CommandList *FindCommand(SicsInterp * self, char *pName)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(pBueffel, pName);
|
||||
if(strlen(pName) > sizeof(pBuffer)){
|
||||
pBueffel = malloc((strlen(pName)+1)*sizeof(char));
|
||||
if(pBueffel == NULL){
|
||||
return NULL;
|
||||
}
|
||||
memset(pBueffel,0,strlen(pName)+1);
|
||||
} else {
|
||||
pBueffel = pBuffer;
|
||||
}
|
||||
|
||||
memset(pBueffel,0,1024);
|
||||
strncpy(pBueffel, pName,1023);
|
||||
strtolower(pBueffel);
|
||||
|
||||
pCmd = TranslateAlias(&self->AList, pBueffel); /* M.Z. */
|
||||
@ -350,11 +361,17 @@ CommandList *FindCommand(SicsInterp * self, char *pName)
|
||||
while (pCurrent) {
|
||||
if (pCurrent->pName != NULL) {
|
||||
if (strcmp(pCurrent->pName, pCmd) == 0) { /* M.Z. */
|
||||
if(pBueffel != pBuffer){
|
||||
free(pBueffel);
|
||||
}
|
||||
return pCurrent;
|
||||
}
|
||||
}
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
if(pBueffel != pBuffer){
|
||||
free(pBueffel);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -504,15 +521,15 @@ static void printAll(SicsInterp * pSics, SConnection * pCon)
|
||||
pCurrent = pSics->pCList;
|
||||
while (pCurrent) {
|
||||
if (iNum == 0) {
|
||||
strcpy(pBueffel, pCurrent->pName);
|
||||
strncpy(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else if (iNum < 4) {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
strcat(pBueffel, "\r\n");
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
iNum = 0;
|
||||
@ -523,7 +540,7 @@ static void printAll(SicsInterp * pSics, SConnection * pCon)
|
||||
|
||||
/* write final entries */
|
||||
if (strlen(pBueffel) > 2) {
|
||||
strcat(pBueffel, "\r\n");
|
||||
strncat(pBueffel, "\r\n",255);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
}
|
||||
}
|
||||
@ -570,7 +587,7 @@ static void printAllTypes(SicsInterp * pSics, SConnection * pCon,
|
||||
pTest = (pDummy) pCurrent->pData;
|
||||
if (NULL != pTest->pDescriptor) {
|
||||
pType = pTest->pDescriptor->name;
|
||||
strcpy(pType_lc, pType);
|
||||
strncpy(pType_lc, pType,255);
|
||||
strtolower(pType_lc);
|
||||
|
||||
LLDnodePtr2First(typeListID);
|
||||
@ -585,7 +602,7 @@ static void printAllTypes(SicsInterp * pSics, SConnection * pCon,
|
||||
/* NB: First checked node is current node, then search to end of list */
|
||||
|
||||
if (0 != LLDnodeFind(typeListID, compareStringNode, (void *) pType)) { /* empty list or 'typename' not found */
|
||||
strcpy(pName_lc, pCurrent->pName);
|
||||
strncpy(pName_lc, pCurrent->pName,255);
|
||||
strtolower(pName_lc);
|
||||
if ((0 == iFiltered) || ((1 == iFiltered) && (0 != strcmp(pType_lc, pName_lc)))) { /*ie Add if unfiltered or pass filter(name!=typename) */
|
||||
LLDstringAdd(typeListID, pType);
|
||||
@ -620,16 +637,16 @@ static void printInterface(SicsInterp * pSics, SConnection * pCon, int id)
|
||||
if (pObj != NULL) {
|
||||
if (pObj->GetInterface(pObj, id) != NULL) {
|
||||
if (iNum == 0) {
|
||||
strcpy(pBueffel, pCurrent->pName);
|
||||
strncpy(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else if (iNum < 4) {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strcat(pBueffel, "\r\n");
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
strncat(pBueffel, "\r\n",255);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
iNum = 0;
|
||||
pBueffel[0] = '\0';
|
||||
@ -666,16 +683,16 @@ static void printMatch(SicsInterp * pSics, SConnection * pCon, char *mask)
|
||||
if (pObj != NULL) {
|
||||
if (!match(mask, pObj->name)) {
|
||||
if (iNum == 0) {
|
||||
strcpy(pBueffel, pCurrent->pName);
|
||||
strncpy(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else if (iNum < 4) {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strcat(pBueffel, "\r\n");
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
strncat(pBueffel, "\r\n",255);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
pBueffel[0] = '\0';
|
||||
iNum = 0;
|
||||
@ -686,7 +703,7 @@ static void printMatch(SicsInterp * pSics, SConnection * pCon, char *mask)
|
||||
}
|
||||
|
||||
/* write final entries */
|
||||
strcat(pBueffel, "\r\n");
|
||||
strncat(pBueffel, "\r\n",255);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
}
|
||||
|
||||
@ -711,16 +728,16 @@ static void printType(SicsInterp * pSics, SConnection * pCon,
|
||||
if (pCurrent->pData != NULL) {
|
||||
if (iHasType(pCurrent->pData, typeName)) {
|
||||
if (iNum == 0) {
|
||||
strcpy(pBueffel, pCurrent->pName);
|
||||
strncpy(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else if (iNum < 4) {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
iNum++;
|
||||
} else {
|
||||
strcat(pBueffel, " ");
|
||||
strcat(pBueffel, pCurrent->pName);
|
||||
strcat(pBueffel, "\r\n");
|
||||
strncat(pBueffel, " ",255);
|
||||
strncat(pBueffel, pCurrent->pName,255);
|
||||
strncat(pBueffel, "\r\n",255);
|
||||
Tcl_DStringAppend(&txt, pBueffel, -1);
|
||||
pBueffel[0] = '\0';
|
||||
iNum = 0;
|
||||
@ -731,7 +748,7 @@ static void printType(SicsInterp * pSics, SConnection * pCon,
|
||||
}
|
||||
|
||||
/* write final entries */
|
||||
strcat(pBueffel, "\r\n");
|
||||
strncat(pBueffel, "\r\n",255);
|
||||
SCWrite(pCon, Tcl_DStringValue(&txt), eValue);
|
||||
Tcl_DStringFree(&txt);
|
||||
}
|
||||
@ -814,12 +831,12 @@ int ListObjects(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
printAllTypes(pSics, pCon, 0);
|
||||
return 1;
|
||||
}
|
||||
strcpy(pType, argv[2]);
|
||||
strncpy(pType, argv[2],255);
|
||||
/* Cater for multi-word types eg 'Environment Monitor' */
|
||||
if (argc > 3) {
|
||||
for (i = 3; i < argc; i++) {
|
||||
strcat(pType, " ");
|
||||
strcat(pType, argv[i]);
|
||||
strncat(pType, " ",255);
|
||||
strncat(pType, argv[i],255);
|
||||
}
|
||||
}
|
||||
printType(pSics, pCon, pType);
|
||||
|
Reference in New Issue
Block a user