Assure NULL terminated strings in rigctl/rigctld

The -r, -p , and -d options 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-06 23:11:35 -06:00
rodzic 7bf119716b
commit b54932ec96
2 zmienionych plików z 6 dodań i 6 usunięć

Wyświetl plik

@ -271,7 +271,7 @@ int main (int argc, char *argv[])
}
if (rig_file)
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN);
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
/*
* ex: RIG_PTT_PARALLEL and /dev/parport0
@ -281,9 +281,9 @@ int main (int argc, char *argv[])
if (dcd_type != RIG_DCD_NONE)
my_rig->state.dcdport.type.dcd = dcd_type;
if (ptt_file)
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN);
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
if (dcd_file)
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN);
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)
my_rig->state.rigport.parm.serial.rate = serial_rate;

Wyświetl plik

@ -304,7 +304,7 @@ int main (int argc, char *argv[])
}
if (rig_file)
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN);
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
/*
* ex: RIG_PTT_PARALLEL and /dev/parport0
@ -314,9 +314,9 @@ int main (int argc, char *argv[])
if (dcd_type != RIG_DCD_NONE)
my_rig->state.dcdport.type.dcd = dcd_type;
if (ptt_file)
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN);
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
if (dcd_file)
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN);
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)
my_rig->state.rigport.parm.serial.rate = serial_rate;