summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Antti Korpimäki2021-10-01 16:35:16 +0200
committerGravatar Antti Korpimäki2021-10-01 16:39:53 +0200
commit84acdd8f95820d5daea3253a674a1b54c0f1588b (patch)
treef3633c5730ca186c7c7b10c403d6bba87138d1a7
parent0a6eba6e2a0c7b4790516677a2ea581f54811ed2 (diff)
downloadxkbcat-84acdd8f95820d5daea3253a674a1b54c0f1588b.tar.gz
xkbcat-84acdd8f95820d5daea3253a674a1b54c0f1588b.zip
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.
-rw-r--r--xkbcat.c11
1 files changed, 10 insertions, 1 deletions
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(); }
}