From d5e95342b5ce6df7da9f0605ebee36c6a5df3482 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 23 Feb 2026 11:20:19 +0100 Subject: [PATCH] swanctl: Check for conflicts with existing and shared options when registering commands --- src/pki/command.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pki/command.c b/src/pki/command.c index 18a3b7ded..5c765ba92 100644 --- a/src/pki/command.c +++ b/src/pki/command.c @@ -222,6 +222,25 @@ void command_register(command_t command) "MAX_COMMANDS\n"); return; } + for (i = 0; i < MAX_COMMANDS && cmds[i].cmd; i++) + { + if (cmds[i].op == command.op) + { + fprintf(stderr, "unable to register command --%s, short option " + "conflicts with --%s\n", command.cmd, cmds[i].cmd); + return; + } + } + for (i = 0; i < countof(shared_options); i++) + { + if (shared_options[i].op == command.op) + { + fprintf(stderr, "unable to register command --%s, short option " + "-%c conflicts with --%s\n", command.cmd, command.op, + shared_options[i].name); + return; + } + } cmds[registered] = command; /* append default options, but not to --help */