From 84acdd8f95820d5daea3253a674a1b54c0f1588b Mon Sep 17 00:00:00 2001 From: Antti Korpimäki Date: Fri, 1 Oct 2021 16:35:16 +0200 Subject: Error when -display option is given without value This was always invalid input, but there was no special handling, so if the `-display` option was given in the last position, the value could be read 1 entry off the end of the `argv` array. This catches that, and gives an informative error. --- xkbcat.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xkbcat.c b/xkbcat.c index b3b2645..b339914 100644 --- a/xkbcat.c +++ b/xkbcat.c @@ -28,8 +28,17 @@ int main(int argc, char * argv[]) { // Get arguments for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-help")) printUsage(); - else if (!strcmp(argv[i], "-display")) xDisplayName = argv[++i]; else if (!strcmp(argv[i], "-up")) printKeyUps = true; + else if (!strcmp(argv[i], "-display")) { + // Read next entry to find value + ++i; + if (i >= argc) { + fprintf(stderr, "No value given to option `-display`\n"); + printUsage(); + exit(5); + } + xDisplayName = argv[i]; + } else { printf("Unexpected argument `%s`\n", argv[i]); printUsage(); } } -- cgit v1.3-2-g0d8e