CDC1700: Fix Coverity identified potential buffer overrun

This commit is contained in:
John Forecast 2017-03-17 08:49:17 -07:00 committed by Mark Pizzolato
parent fcf3104f6a
commit b64f3cd1c7
2 changed files with 841 additions and 834 deletions

File diff suppressed because it is too large Load diff

View file

@ -340,10 +340,11 @@ char *textRep(uint16 start, uint16 len)
{
int i;
static char text[64];
size_t text_space = sizeof (text) - 1;
text[0] = '\0';
for (i = 0; (i < (2 * len)) && (strlen(text) < MAXTEXT); i++) {
for (i = 0; (i < (2 * len)) && (text_space >= MAXTEXT); i++) {
uint16 ch = M[start];
if ((i & 1) == 0)
@ -351,7 +352,8 @@ char *textRep(uint16 start, uint16 len)
else start++;
ch &= 0x7F;
strcat(text, charRep[ch]);
strncpy(&text[strlen(text)], charRep[ch], text_space);
text_space -= strlen(charRep[ch]);
}
return text;
}