From f454cff0b71bc1dbcbfe2d3918d7387049be26f4 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Wed, 1 Jul 2020 08:52:44 -0500 Subject: [PATCH] Add check for -s switch on all utils to ensure integer is entered --- tests/ampctl.c | 8 +++++++- tests/ampctld.c | 8 +++++++- tests/rigctl.c | 8 +++++++- tests/rigctl_parse.c | 6 +++--- tests/rigctlcom.c | 8 +++++++- tests/rigctld.c | 8 +++++++- tests/rigmem.c | 8 +++++++- tests/rigsmtr.c | 8 +++++++- tests/rigswr.c | 8 +++++++- tests/rotctl.c | 8 +++++++- tests/rotctld.c | 8 +++++++- 11 files changed, 73 insertions(+), 13 deletions(-) diff --git a/tests/ampctl.c b/tests/ampctl.c index 1fc31f271..1e7e93817 100644 --- a/tests/ampctl.c +++ b/tests/ampctl.c @@ -142,6 +142,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, @@ -191,7 +192,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/ampctld.c b/tests/ampctld.c index dde43452d..e5244eaed 100644 --- a/tests/ampctld.c +++ b/tests/ampctld.c @@ -185,6 +185,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); @@ -230,7 +231,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rigctl.c b/tests/rigctl.c index 901a7e817..2c9d7800f 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -158,6 +158,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, @@ -353,7 +354,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index a4e9d084d..31c1d28c5 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -4085,9 +4085,9 @@ declare_proto_rig(dump_state) // backward compatible as new values will just generate warnings if (chk_vfo_executed) // for 3.3 compatiblility { - fprintf(fout, "vfo_ops=0x%x\n", rig->caps->vfo_ops); - fprintf(fout, "ptt_type=0x%x\n", rig->state.pttport.type.ptt); - fprintf(fout, "done\n"); + fprintf(fout, "vfo_ops=0x%x\n", rig->caps->vfo_ops); + fprintf(fout, "ptt_type=0x%x\n", rig->state.pttport.type.ptt); + fprintf(fout, "done\n"); } #if 0 // why isn't this implemented? Does anybody care? diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index 118d11f3c..eda52b98a 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -227,6 +227,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, @@ -393,7 +394,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'S': diff --git a/tests/rigctld.c b/tests/rigctld.c index cc00e516c..2b0baea76 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -265,6 +265,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, @@ -442,7 +443,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rigmem.c b/tests/rigmem.c index 029f77e45..ca0796638 100644 --- a/tests/rigmem.c +++ b/tests/rigmem.c @@ -115,6 +115,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); @@ -170,7 +171,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rigsmtr.c b/tests/rigsmtr.c index 071814e20..c27cb7c81 100644 --- a/tests/rigsmtr.c +++ b/tests/rigsmtr.c @@ -99,6 +99,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); @@ -154,7 +155,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rigswr.c b/tests/rigswr.c index 2901fe421..62bb949e5 100644 --- a/tests/rigswr.c +++ b/tests/rigswr.c @@ -89,6 +89,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); @@ -144,7 +145,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rotctl.c b/tests/rotctl.c index f90fade14..dbcae7486 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -147,6 +147,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, @@ -196,7 +197,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C': diff --git a/tests/rotctld.c b/tests/rotctld.c index 7c51f9bb3..ffc33bbcd 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -179,6 +179,7 @@ int main(int argc, char *argv[]) { int c; int option_index = 0; + char dummy[2]; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); @@ -224,7 +225,12 @@ int main(int argc, char *argv[]) exit(1); } - serial_rate = atoi(optarg); + if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1) + { + fprintf(stderr, "Invalid baud rate of %s\n", optarg); + exit(1); + } + break; case 'C':