Assure NULL terminated strings in tests programs.

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:36:50 -06:00
rodzic 59516cbb26
commit 1229a0a42a
10 zmienionych plików z 37 dodań i 37 usunięć

Wyświetl plik

@ -50,7 +50,7 @@ int main (int argc, char *argv[])
exit(1); /* whoops! something went wrong (mem alloc?) */
}
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN);
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
if (rig_open(my_rig))
exit(2);

Wyświetl plik

@ -29,7 +29,7 @@ int main() {
my_rig = rig_init(RIG_MODEL_TT565); // your rig model.
/* Set up serial port, baud rate */
rig_file = "/dev/ttyUSB0"; // your serial device
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN);
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
my_rig->state.rigport.parm.serial.rate = 57600; // your baud rate
/* Open my rig */
retcode = rig_open(my_rig);

Wyświetl plik

@ -38,7 +38,7 @@ int main (int argc, char *argv[])
myport.parm.serial.stop_bits = 1;
myport.parm.serial.parity = RIG_PARITY_NONE;
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN);
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
rig_load_all_backends();
myrig_model = rig_probe(&myport);
@ -60,7 +60,7 @@ int main (int argc, char *argv[])
my_rig->caps->version, rig_strstatus(my_rig->caps->status));
printf("Serial speed: %d bauds\n", my_rig->state.rigport.parm.serial.rate);
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN);
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN - 1);
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {

Wyświetl plik

@ -228,7 +228,7 @@ int main (int argc, char *argv[])
}
if (rig_file)
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN);
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)

Wyświetl plik

@ -212,7 +212,7 @@ int main (int argc, char *argv[])
}
if (rig_file)
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN);
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)
@ -257,7 +257,7 @@ int main (int argc, char *argv[])
}
if (rot_file)
strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN);
strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (rot_serial_rate != 0)

Wyświetl plik

@ -202,10 +202,10 @@ int main (int argc, char *argv[])
if (ptt_type != RIG_PTT_NONE)
rig->state.pttport.type.ptt = ptt_type;
if (ptt_file)
strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN);
strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
if (rig_file)
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN);
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)

Wyświetl plik

@ -193,7 +193,7 @@ int main (int argc, char *argv[])
}
if (rot_file)
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN);
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)

Wyświetl plik

@ -231,7 +231,7 @@ int main (int argc, char *argv[])
}
if (rot_file)
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN);
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)

Wyświetl plik

@ -37,7 +37,7 @@ int main (int argc, char *argv[])
myport.parm.serial.stop_bits = 1;
myport.parm.serial.parity = RIG_PARITY_NONE;
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN);
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);
rig_load_all_backends();
myrig_model = rig_probe(&myport);
@ -53,7 +53,7 @@ int main (int argc, char *argv[])
exit(1); /* whoops! something went wrong (mem alloc?) */
}
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN);
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN - 1);
retcode = rig_open(my_rig);
if (retcode != RIG_OK) {

Wyświetl plik

@ -45,7 +45,7 @@ int main (int argc, char *argv[])
exit(1); /* whoops! something went wrong (mem alloc?) */
}
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN);
strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);
if (rig_open(my_rig))
exit(2);