Assure NULL terminated strings in src files.

Various strncpy operations could result in a port pathname that is not a
NULL terminated string as the allowed string length is the same size as
the buffer per the strncpy manual page.  This is corrected by assuring
that the allowed length is FILPATHLEN - 1.
Hamlib-1.2.15
Nate Bargmann 2012-01-07 20:50:34 -06:00
rodzic 1229a0a42a
commit b31cc6ecd9
2 zmienionych plików z 8 dodań i 8 usunięć

Wyświetl plik

@ -292,7 +292,7 @@ RIG * HAMLIB_API rig_init(rig_model_t rig_model)
switch (caps->port_type) {
case RIG_PORT_SERIAL:
strncpy(rs->rigport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN);
strncpy(rs->rigport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1);
rs->rigport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
rs->rigport.parm.serial.data_bits = caps->serial_data_bits;
rs->rigport.parm.serial.stop_bits = caps->serial_stop_bits;
@ -301,16 +301,16 @@ RIG * HAMLIB_API rig_init(rig_model_t rig_model)
break;
case RIG_PORT_PARALLEL:
strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN - 1);
break;
case RIG_PORT_NETWORK:
case RIG_PORT_UDP_NETWORK:
strncpy(rs->rigport.pathname, "127.0.0.1:4532", FILPATHLEN);
strncpy(rs->rigport.pathname, "127.0.0.1:4532", FILPATHLEN - 1);
break;
default:
strncpy(rs->rigport.pathname, "", FILPATHLEN);
strncpy(rs->rigport.pathname, "", FILPATHLEN - 1);
}
rs->rigport.write_delay = caps->write_delay;

Wyświetl plik

@ -223,7 +223,7 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
switch (caps->port_type) {
case RIG_PORT_SERIAL:
strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN);
strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1);
rs->rotport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
rs->rotport.parm.serial.data_bits = caps->serial_data_bits;
rs->rotport.parm.serial.stop_bits = caps->serial_stop_bits;
@ -232,16 +232,16 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
break;
case RIG_PORT_PARALLEL:
strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN - 1);
break;
case RIG_PORT_NETWORK:
case RIG_PORT_UDP_NETWORK:
strncpy(rs->rotport.pathname, "127.0.0.1:4533", FILPATHLEN);
strncpy(rs->rotport.pathname, "127.0.0.1:4533", FILPATHLEN - 1);
break;
default:
strncpy(rs->rotport.pathname, "", FILPATHLEN);
strncpy(rs->rotport.pathname, "", FILPATHLEN - 1);
}
rs->min_el = caps->min_el;