- 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:
@ -587,10 +587,10 @@ static void encodeTerminator(char *result, char *terminator)
|
||||
result[0] = '\0';
|
||||
}
|
||||
len = strlen(terminator);
|
||||
sprintf(pBuffer, "0x%x", (int) terminator[0]);
|
||||
snprintf(pBuffer,sizeof(pBuffer)-1, "0x%x", (int) terminator[0]);
|
||||
strcpy(result, pBuffer);
|
||||
for (i = 1; i < len; i++) {
|
||||
sprintf(pBuffer, "0x%x", (int) terminator[i]);
|
||||
snprintf(pBuffer,sizeof(pBuffer)-1, "0x%x", (int) terminator[i]);
|
||||
strcat(result, pBuffer);
|
||||
}
|
||||
}
|
||||
@ -646,7 +646,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics,
|
||||
check for arguments
|
||||
*/
|
||||
if (argc < 2) {
|
||||
sprintf(pError, "ERROR: insufficient no of arguments to %s", argv[0]);
|
||||
snprintf(pError,sizeof(pError)-1, "ERROR: insufficient no of arguments to %s", argv[0]);
|
||||
SCWrite(pCon, pError, eError);
|
||||
return 0;
|
||||
}
|
||||
@ -662,7 +662,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics,
|
||||
return 1;
|
||||
} else {
|
||||
encodeTerminator(pBuffer, self->sendTerminator);
|
||||
sprintf(pError, "%s.sendTerminator = \"%s\"", argv[0], pBuffer);
|
||||
snprintf(pError,sizeof(pError)-1, "%s.sendTerminator = \"%s\"", argv[0], pBuffer);
|
||||
SCWrite(pCon, pError, eValue);
|
||||
return 1;
|
||||
}
|
||||
@ -676,7 +676,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics,
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
sprintf(pError, "%s.Timeout = %d", argv[0], self->timeout);
|
||||
snprintf(pError,sizeof(pError)-1, "%s.Timeout = %d", argv[0], self->timeout);
|
||||
SCWrite(pCon, pError, eValue);
|
||||
return 1;
|
||||
}
|
||||
@ -694,7 +694,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics,
|
||||
return 1;
|
||||
} else {
|
||||
encodeTerminator(pBuffer, self->replyTerminator);
|
||||
sprintf(pError, "%s.replyTerminator = \"%s\"", argv[0], pBuffer);
|
||||
snprintf(pError,sizeof(pError)-1, "%s.replyTerminator = \"%s\"", argv[0], pBuffer);
|
||||
SCWrite(pCon, pError, eValue);
|
||||
return 1;
|
||||
}
|
||||
@ -786,7 +786,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics,
|
||||
} else if (strcmp(argv[1], "init") == 0) {
|
||||
iRet = initRS232(self);
|
||||
if (iRet != 1) {
|
||||
sprintf(pError,
|
||||
snprintf(pError,sizeof(pError)-1,
|
||||
"ERROR: reinitializing connection to %s at %d failed",
|
||||
self->pHost, self->iPort);
|
||||
SCWrite(pCon, pError, eError);
|
||||
@ -796,7 +796,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics,
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
sprintf(pError, "ERROR: %s does not understand %s", argv[0], argv[1]);
|
||||
snprintf(pError,sizeof(pError)-1, "ERROR: %s does not understand %s", argv[0], argv[1]);
|
||||
SCWrite(pCon, pError, eError);
|
||||
return 0;
|
||||
}
|
||||
@ -830,7 +830,7 @@ int RS232Factory(SConnection * pCon, SicsInterp * pSics,
|
||||
|
||||
status = initRS232(pNew);
|
||||
if (status != 1) {
|
||||
sprintf(pError, "ERROR: failed to connect to %s at port %d",
|
||||
snprintf(pError,sizeof(pError)-1, "ERROR: failed to connect to %s at port %d",
|
||||
pNew->pHost, pNew->iPort);
|
||||
SCWrite(pCon, pError, eError);
|
||||
}
|
||||
@ -840,7 +840,7 @@ int RS232Factory(SConnection * pCon, SicsInterp * pSics,
|
||||
*/
|
||||
iRet = AddCommand(pSics, argv[1], RS232Action, KillAndFreeRS232, pNew);
|
||||
if (!iRet) {
|
||||
sprintf(pError, "ERROR: duplicate command %s not created", argv[1]);
|
||||
snprintf(pError,sizeof(pError)-1, "ERROR: duplicate command %s not created", argv[1]);
|
||||
SCWrite(pCon, pError, eError);
|
||||
KillAndFreeRS232(pNew);
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user