[PATCH 4/4] vsh: Ensure that bool --options don't have completer

Michal Privoznik mprivozn at redhat.com
Fri Sep 17 08:13:10 UTC 2021


Let's check whether a boolean --option doesn't have completer or
completer_flags set. These options are just flags and don't
accept any value, thus they can't have any completer.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tools/vsh.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 3d5fef84f0..7343387842 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -337,8 +337,16 @@ vshCmddefCheckInternals(vshControl *ctl,
             virBufferStrcat(&complbuf, opt->name, ", ", NULL);
 
         switch (opt->type) {
-        case VSH_OT_STRING:
         case VSH_OT_BOOL:
+            if (opt->completer || opt->completer_flags) {
+                vshError(ctl, _("bool parameter '%s' of command '%s' has completer set"),
+                         opt->name, cmd->name);
+                return -1;
+            }
+
+            G_GNUC_FALLTHROUGH;
+
+        case VSH_OT_STRING:
             if (opt->flags & VSH_OFLAG_REQ) {
                 vshError(ctl, _("parameter '%s' of command '%s' misused VSH_OFLAG_REQ"),
                          opt->name, cmd->name);
-- 
2.32.0




More information about the libvir-list mailing list