Change sprintf to SNPRINTF in misc.c, network.c, and rig.c

https://github.com/Hamlib/Hamlib/issues/857
pull/943/head
Mike Black W9MDB 2022-01-18 15:07:49 -06:00
rodzic f801244fb6
commit e2bb11aa4c
4 zmienionych plików z 5 dodań i 5 usunięć

Wyświetl plik

@ -1962,7 +1962,7 @@ vfo_t HAMLIB_API vfo_fixup(RIG *rig, vfo_t vfo, split_t split)
return vfo;
}
int HAMLIB_API parse_hoststr(char *hoststr, char host[256], char port[6])
int HAMLIB_API parse_hoststr(char *hoststr, int hoststr_len, char host[256], char port[6])
{
unsigned int net1, net2, net3, net4, net5, net6, net7, net8;
char dummy[6], link[32], *p;
@ -2064,7 +2064,7 @@ int HAMLIB_API parse_hoststr(char *hoststr, char host[256], char port[6])
if (sscanf(hoststr, ":%5[0-9]%1s", port,
dummy) == 1) // just a port if you please
{
snprintf(hoststr, sizeof(hoststr), "%s:%s\n", "localhost", port);
snprintf(hoststr, hoststr_len, "%s:%s\n", "localhost", port);
rig_debug(RIG_DEBUG_VERBOSE, "%s: hoststr=%s\n", __func__, hoststr);
return RIG_OK;
}

Wyświetl plik

@ -115,7 +115,7 @@ extern HAMLIB_EXPORT(vfo_t) vfo_fixup(RIG *rig, vfo_t vfo, split_t split);
extern HAMLIB_EXPORT(vfo_t) vfo_fixup2a(RIG *rig, vfo_t vfo, split_t split, const char *func, const int line);
#define vfo_fixup(r,v,s) vfo_fixup2a(r,v,s,__func__,__LINE__)
extern HAMLIB_EXPORT(int) parse_hoststr(char *hoststr, char host[256], char port[6]);
extern HAMLIB_EXPORT(int) parse_hoststr(char *hoststr, int hoststr_len, char host[256], char port[6]);
extern HAMLIB_EXPORT(uint32_t) CRC32_function(uint8_t *buf, uint32_t len);

Wyświetl plik

@ -243,7 +243,7 @@ int network_open(hamlib_port_t *rp, int default_port)
{
if (strlen(rp->pathname))
{
status = parse_hoststr(rp->pathname, hoststr, portstr);
status = parse_hoststr(rp->pathname, sizeof(rp->pathname), hoststr, portstr);
if (status != RIG_OK) { RETURNFUNC(status); }

Wyświetl plik

@ -724,7 +724,7 @@ int HAMLIB_API rig_open(RIG *rig)
if (strlen(rs->rigport.pathname) > 0)
{
char hoststr[256], portstr[6];
status = parse_hoststr(rs->rigport.pathname, hoststr, portstr);
status = parse_hoststr(rs->rigport.pathname, sizeof(rs->rigport.pathname), hoststr, portstr);
if (status == RIG_OK) { is_network = 1; }
}