Change all sprintf to snprintf in rigmatrix.c and check for buffer overflow

https://github.com/Hamlib/Hamlib/issues/857
pull/928/head
Mike Black W9MDB 2022-01-08 16:05:45 -06:00
rodzic e63fbf0812
commit b358437cea
1 zmienionych plików z 14 dodań i 2 usunięć

Wyświetl plik

@ -749,7 +749,13 @@ int main(int argc, char *argv[])
}
bitmap_level |= level;
pbuf += sprintf(pbuf, "<TD>%s</TD>", s);
nbytes = strlen("<TD></TD>") + strlen(s) + 1;
nbytes_total += nbytes;
pbuf += snprintf(pbuf, sizeof(pbuf)-nbytes_total, "<TD>%s</TD>", s);
if (strlen(pbuf) > sizeof(pbuf) + nbytes)
{
printf("Buffer overflow in %s\n", __func__);
}
}
printf("Set level");
@ -785,7 +791,13 @@ int main(int argc, char *argv[])
}
bitmap_parm |= parm;
pbuf += sprintf(pbuf, "<TD>%s</TD>", s);
nbytes = strlen("<TD></TD>") + strlen(s) + 1;
nbytes_total += nbytes;
pbuf += snprintf(pbuf, sizeof(pbuf)-nbytes_total, "<TD>%s</TD>", s);
if (strlen(pbuf) > sizeof(pbuf) + nbytes)
{
printf("Buffer overflow in %s\n", __func__);
}
}
printf("Set parm");