From nobody Thu Sep 19 01:22:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1716801723485557.0548371379518; Mon, 27 May 2024 02:22:03 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5C44F1C16; Mon, 27 May 2024 05:22:02 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1338D1B98; Mon, 27 May 2024 05:19:24 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 99D46191C; Mon, 27 May 2024 05:19:08 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 22B3C1919 for ; Mon, 27 May 2024 05:19:08 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-J04rAKteMM6juqf0QA6l0g-1; Mon, 27 May 2024 05:19:06 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD5D429AA3A2 for ; Mon, 27 May 2024 09:19:05 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7981A40005B for ; Mon, 27 May 2024 09:19:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716801547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=063QWXJrgKfWAJzNPM1lzCnAwiESadtl7cxfOeeldMo=; b=R22IPNQ6aHf/vemLROlEOVo4PuLXFNkAgjX0B+xW+9tlVJZEMzhFIxK8HQyfEXWJtfT0mx 8xwHeqJnblgD0glbLbqR1GPtXTGZp4ueKLe9M0T/n8jLcyGZzzwnZOh1Ix9nOqCNBU9Z0d mRSNUwiIyVfX8HOOltSk80pETslRyEg= X-MC-Unique: J04rAKteMM6juqf0QA6l0g-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 4/6] vsh: Close stderr among with stdin in cmdComplete Date: Mon, 27 May 2024 11:18:52 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DKLWYPY27STDL3FN3KWUOSS2VDVWYBUE X-Message-ID-Hash: DKLWYPY27STDL3FN3KWUOSS2VDVWYBUE X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716801729623100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Our completer callbacks must refrain from printing anything onto stderr, but unfortunately that's not how service code around behaves. It may call vshError() and what not. Rather trying to fix all possible paths (just consider opening a connection), just close the stderr. We're already closing stdin. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- tools/vsh.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 61a3066f49..de869248b4 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3488,17 +3488,20 @@ const vshCmdInfo info_complete =3D { =20 #ifdef WITH_READLINE =20 -static virOnceControl vshCmdCompleteCloseStdinOnce =3D VIR_ONCE_CONTROL_IN= ITIALIZER; +static virOnceControl vshCmdCompleteCloseStdinStderrOnce =3D VIR_ONCE_CONT= ROL_INITIALIZER; =20 static void -vshCmdCompleteCloseStdin(void) +vshCmdCompleteCloseStdinStderr(void) { /* In non-interactive mode which is how the 'complete' command is inte= nded * to be used we need to ensure that any authentication callback will = not - * attempt to read any input which would break the completion */ + * attempt to read any input which would break the completion. Similar= ly, + * printing anything onto stderr should be avoided. */ int stdin_fileno =3D STDIN_FILENO; + int stderr_fileno =3D STDERR_FILENO; =20 VIR_FORCE_CLOSE(stdin_fileno); + VIR_FORCE_CLOSE(stderr_fileno); } =20 =20 @@ -3519,7 +3522,7 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd) * need to prevent auth hooks reading any input. Therefore, we * have to close stdin and then connect ourselves. */ if (!ctl->imode) { - if (virOnce(&vshCmdCompleteCloseStdinOnce, vshCmdCompleteCloseStdi= n) < 0) + if (virOnce(&vshCmdCompleteCloseStdinStderrOnce, vshCmdCompleteClo= seStdinStderr) < 0) return false; } =20 --=20 2.44.1