kopia lustrzana https://github.com/Hamlib/Hamlib
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
rodzic
59516cbb26
commit
1229a0a42a
|
@ -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);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* This is a elementary program calling Hamlib to do some useful things.
|
||||
*
|
||||
*
|
||||
* Edit to specify your rig model and serial port, and baud rate
|
||||
* before compiling.
|
||||
* To compile:
|
||||
|
@ -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);
|
||||
|
@ -38,7 +38,7 @@ int main() {
|
|||
printf("Rig_info: '%s'\n", info_buf);
|
||||
|
||||
/* Note: As a general practice, we should check to see if a given
|
||||
* function is within the rig's capabilities before calling it, but
|
||||
* function is within the rig's capabilities before calling it, but
|
||||
* we are simplifying here. Also, we should check each call's returned
|
||||
* status in case of error. (That's an inelegant way to catch an unsupported
|
||||
* operation.)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Hamlib rig_bench program
|
||||
*/
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
|||
#define SERIAL_PORT "/dev/ttyS0"
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
int retcode; /* generic return code from functions */
|
||||
rig_model_t myrig_model;
|
||||
|
@ -26,7 +26,7 @@ int main (int argc, char *argv[])
|
|||
rig_set_debug(RIG_DEBUG_ERR);
|
||||
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
|
||||
if (argc < 2) {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Hamlib sample program
|
||||
*/
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
|||
#define SERIAL_PORT "/dev/ttyS0"
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
freq_t freq; /* frequency */
|
||||
rmode_t rmode; /* radio mode of operation */
|
||||
|
@ -25,7 +25,7 @@ int main (int argc, char *argv[])
|
|||
printf("testrig:hello, I am your main() !\n");
|
||||
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
|
||||
if (argc < 2) {
|
||||
|
@ -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);
|
||||
|
@ -46,14 +46,14 @@ int main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
my_rig = rig_init(myrig_model);
|
||||
|
||||
|
||||
if (!my_rig) {
|
||||
fprintf(stderr,"Unknown rig num: %d\n", myrig_model);
|
||||
fprintf(stderr,"Please check riglist.h\n");
|
||||
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) {
|
||||
|
@ -87,11 +87,11 @@ int main (int argc, char *argv[])
|
|||
* Examples of checking return code are further down.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* 10m FM Narrow */
|
||||
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 28350125); /* 10m */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
|
||||
rig_passband_narrow(my_rig, RIG_MODE_FM));
|
||||
sleep(3); /* so you can see it -- FS */
|
||||
|
||||
|
@ -116,7 +116,7 @@ int main (int argc, char *argv[])
|
|||
/* 80m AM NArrow */
|
||||
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3980000); /* 80m */
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM,
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM,
|
||||
rig_passband_narrow(my_rig, RIG_MODE_FM));
|
||||
sleep(3);
|
||||
|
||||
|
@ -154,19 +154,19 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
}
|
||||
|
||||
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL);
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_mode: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
}
|
||||
|
||||
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON ); /* stand back ! */
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
@ -174,7 +174,7 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
@ -192,7 +192,7 @@ int main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
||||
|
||||
|
||||
if (retcode == RIG_OK ) {
|
||||
printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Hamlib sample program to test transceive mode (async event)
|
||||
*/
|
||||
|
||||
|
@ -22,7 +22,7 @@ int myfreq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg)
|
|||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
int retcode; /* generic return code from functions */
|
||||
int i, count = 0;
|
||||
|
@ -35,7 +35,7 @@ int main (int argc, char *argv[])
|
|||
printf("testrig:hello, I am your main() !\n");
|
||||
|
||||
/*
|
||||
* allocate memory, setup & open port
|
||||
* allocate memory, setup & open port
|
||||
*/
|
||||
|
||||
my_rig = rig_init(atoi(argv[1]));
|
||||
|
@ -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);
|
||||
|
@ -57,13 +57,13 @@ int main (int argc, char *argv[])
|
|||
* Must add checking of functionality map prior to command execution -- FS
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000);
|
||||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
}
|
||||
|
||||
rig_set_freq_callback(my_rig, myfreq_event, (rig_ptr_t)&count);
|
||||
|
||||
|
@ -71,7 +71,7 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (retcode != RIG_OK ) {
|
||||
printf("rig_set_trn: error = %s \n", rigerror(retcode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i=0;i<12;i++)
|
||||
|
|
Ładowanie…
Reference in New Issue