ddsperf argument checking improvements

Inspired by Coverity warnings.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2020-02-18 10:37:56 +01:00 committed by eboasson
parent ef047d6bd5
commit 9a0ad5e2f5

View file

@ -1749,7 +1749,7 @@ static void set_mode_ping (int *xoptind, int xargc, char * const xargv[])
{
int pos = 0, mult = 1;
double ping_rate;
if (strcmp (xargv[*xoptind], "inf") == 0 && lookup_multiplier (frequency_units, xargv[*xoptind] + 3) > 0)
if (strncmp (xargv[*xoptind], "inf", 3) == 0 && lookup_multiplier (frequency_units, xargv[*xoptind] + 3) > 0)
{
ping_intv = 0;
}
@ -1891,12 +1891,12 @@ int main (int argc, char *argv[])
while ((opt = getopt (argc, argv, "cd:D:i:n:k:uLK:T:Q:R:h")) != EOF)
{
int pos;
switch (opt)
{
case 'c': collect_stats = true; break;
case 'd': {
char *col;
int pos;
(void) ddsrt_strlcpy (netload_if, optarg, sizeof (netload_if));
if ((col = strrchr (netload_if, ':')) == NULL || col == netload_if ||
(sscanf (col+1, "%lf%n", &netload_bw, &pos) != 1 || (col+1)[pos] != 0))
@ -1917,10 +1917,9 @@ int main (int argc, char *argv[])
else if (strcmp (optarg, "OU") == 0) topicsel = OU;
else if (strcmp (optarg, "UK16") == 0) topicsel = UK16;
else if (strcmp (optarg, "UK1024") == 0) topicsel = UK1024;
else error3 ("%s: unknown topic\n", optarg);
else error3 ("-T %s: unknown topic\n", optarg);
break;
case 'Q': {
int pos;
double d;
unsigned long n;
if (sscanf (optarg, "rss:%lf%n", &d, &pos) == 1 && (optarg[pos] == 0 || optarg[pos] == '%')) {
@ -1939,7 +1938,12 @@ int main (int argc, char *argv[])
}
break;
}
case 'R': tref = 0; sscanf (optarg, "%"SCNd64, &tref); break;
case 'R': {
tref = 0;
if (sscanf (optarg, "%"SCNd64"%n", &tref, &pos) != 1 || optarg[pos] != 0)
error3 ("-R %s: invalid reference time\n", optarg);
break;
}
case 'h': default: usage (); break;
}
}