Commit 9a1dc49451a7 ("selftests: watchdog: accept multiple params on command line") made possible performing multiple commands between opening and closing of the watchdog device. However, it left some hardcoded indexes in the argv[], which can lead to segmentation fault under certain combinations of arguments (e.g. [1] and [2]). Fix this. [1] ./watchdog-test -p 1 -t [2] ./watchdog-test -t 1 -p Fixes: 9a1dc49451a7 ("selftests: watchdog: accept multiple params on command line") Reported-by: Timur Tabi <timur@xxxxxxxxxxxxxx> Signed-off-by: Eugeniu Rosca <erosca@xxxxxxxxxxxxxx> --- tools/testing/selftests/watchdog/watchdog-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c index a74c9d739d07..11d3e8cfb20c 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c @@ -75,13 +75,13 @@ int main(int argc, char *argv[]) ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); if (!ret) printf("Watchdog card enabled.\n"); - } else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) { + } else if (!strncasecmp(argv[i], "-t", 2) && argv[i + 1]) { flags = atoi(argv[i + 1]); ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags); if (!ret) printf("Watchdog timeout set to %u seconds.\n", flags); i++; - } else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) { + } else if (!strncasecmp(argv[i], "-p", 2) && argv[i + 1]) { ping_rate = strtoul(argv[i + 1], NULL, 0); printf("Watchdog ping rate set to %u seconds.\n", ping_rate); i++; -- 2.13.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html