From nobody Sun Apr 28 19:56:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1519809660528200.52563809507387; Wed, 28 Feb 2018 01:21:00 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6E82C047B94; Wed, 28 Feb 2018 09:20:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0443D6018B; Wed, 28 Feb 2018 09:20:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1AEA118033EB; Wed, 28 Feb 2018 09:20:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1S9Kt7M026311 for ; Wed, 28 Feb 2018 04:20:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7EA9B213AEF8; Wed, 28 Feb 2018 09:20:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09315213AEF5; Wed, 28 Feb 2018 09:20:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 28 Feb 2018 10:20:51 +0100 Message-Id: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: jcfaracco@gmail.com Subject: [libvirt] [PATCH] vshCommandOpt: Do more checking if skipChecks is set X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 28 Feb 2018 09:20:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently if cmd->skipChecks is set (done only from completers) some basic checks are skipped because we're working over partially parsed command. See a26ff63ae4 for more detailed explanation. Anyway, the referenced commit was too aggressive in disabling checks and effectively returned success even in clear case of failure. For instance: # domif-getlink --interface causes virshDomainInterfaceCompleter() to be called, which calls virshDomainGetXML() which eventually calls vshCommandOptStringReq(.., name =3D "domain"); The --domain argument is required for the command and if not present -1 should be returned to tell the caller the argument was not found. Well, zero is returned meaning the argument was not found but it's not required either. Signed-off-by: Michal Privoznik --- tools/vsh.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 37c292a03..73ec007e5 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -817,18 +817,17 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vs= hCmdOpt **opt, /* See if option is valid and/or required. */ *opt =3D NULL; =20 - if (!cmd->skipChecks) { - while (valid && valid->name) { - if (STREQ(name, valid->name)) - break; - valid++; - } + while (valid && valid->name) { + if (STREQ(name, valid->name)) + break; + valid++; + } =20 + if (!cmd->skipChecks) assert(valid && (!needData || valid->type !=3D VSH_OT_BOOL)); =20 - if (valid->flags & VSH_OFLAG_REQ) - ret =3D -1; - } + if (valid && valid->flags & VSH_OFLAG_REQ) + ret =3D -1; =20 /* See if option is present on command line. */ while (candidate) { @@ -1065,7 +1064,8 @@ vshCommandOptStringReq(vshControl *ctl, error =3D N_("Option argument is empty"); =20 if (error) { - vshError(ctl, _("Failed to get option '%s': %s"), name, _(error)); + if (!cmd->skipChecks) + vshError(ctl, _("Failed to get option '%s': %s"), name, _(erro= r)); return -1; } =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list