From c219668c4d2459579af77f6a2fb782337ca0fbae Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 29 Mar 2022 19:38:44 +0200 Subject: tools: Fix SEGV in oping with missing param values If not passed a value for the last parameter, oping would SEGV. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/tools/oping/oping.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/tools/oping/oping.c b/src/tools/oping/oping.c index 62eb94d5..e215b217 100644 --- a/src/tools/oping/oping.c +++ b/src/tools/oping/oping.c @@ -175,30 +175,36 @@ int main(int argc, server.quiet = false; while (argc > 0) { - if (strcmp(*argv, "-i") == 0 || - strcmp(*argv, "--interval") == 0) { + if ((strcmp(*argv, "-i") == 0 || + strcmp(*argv, "--interval") == 0) && + argc > 1) { client.interval = strtol(*(++argv), &rem, 10); client.interval *= time_mul(rem); --argc; - } else if (strcmp(*argv, "-n") == 0 || - strcmp(*argv, "--server-name") == 0) { + } else if ((strcmp(*argv, "-n") == 0 || + strcmp(*argv, "--server-name") == 0) && + argc > 1) { client.s_apn = *(++argv); --argc; - } else if (strcmp(*argv, "-c") == 0 || - strcmp(*argv, "--count") == 0) { + } else if ((strcmp(*argv, "-c") == 0 || + strcmp(*argv, "--count") == 0) && + argc > 1) { client.count = strtol(*(++argv), &rem, 10); --argc; - } else if (strcmp(*argv, "-d") == 0 || - strcmp(*argv, "--duration") == 0) { + } else if ((strcmp(*argv, "-d") == 0 || + strcmp(*argv, "--duration") == 0) && + argc > 1) { duration = strtol(*(++argv), &rem, 10); duration *= time_mul(rem); --argc; - } else if (strcmp(*argv, "-s") == 0 || - strcmp(*argv, "--size") == 0) { + } else if ((strcmp(*argv, "-s") == 0 || + strcmp(*argv, "--size") == 0) && + argc > 1) { client.size = strtol(*(++argv), &rem, 10); --argc; - } else if (strcmp(*argv, "-q") == 0 || - strcmp(*argv, "--qos") == 0) { + } else if ((strcmp(*argv, "-q") == 0 || + strcmp(*argv, "--qos") == 0) && + argc > 1) { qos = *(++argv); --argc; } else if (strcmp(*argv, "-l") == 0 || -- cgit v1.2.3