From a1a22b0b1cbe51bc9d923a73f131429357cb0640 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 17 Sep 2021 09:52:43 +0200 Subject: [PATCH] vsh: Extend checks for aliased commands MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If a command is an alias, then it can only have .name, .flags and .alias set and .flags should contain just VSH_CMD_FLAG_ALIAS. Check if that's the case in self-test. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- tools/vsh.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/vsh.c b/tools/vsh.c index 9057310077..dd6930730d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -290,6 +290,26 @@ vshCmddefCheckInternals(vshControl *ctl, return -1; } + if (cmd->handler) { + vshError(ctl, _("command '%s' has handler set"), cmd->name); + return -1; + } + + if (cmd->opts) { + vshError(ctl, _("command '%s' has options set"), cmd->name); + return -1; + } + + if (cmd->info) { + vshError(ctl, _("command '%s' has info set"), cmd->name); + return -1; + } + + if (cmd->flags & ~VSH_CMD_FLAG_ALIAS) { + vshError(ctl, _("command '%s' has multiple flags set"), cmd->name); + return -1; + } + /* we don't need to continue as the real command will be checked separately */ return 0; } -- 2.47.2