From nobody Sat May 18 18:58:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) 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 1714035920750603.5810594654348; Thu, 25 Apr 2024 02:05:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 926632306; Thu, 25 Apr 2024 05:05:19 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 94A4D22D4; Thu, 25 Apr 2024 05:04:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 130BC1E72; Thu, 25 Apr 2024 05:04:07 -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 A3B221E74 for ; Thu, 25 Apr 2024 05:04:06 -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-322-hlXgcj7pMfu6qgy3GjJvRw-1; Thu, 25 Apr 2024 05:04:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 B760A3C0244F for ; Thu, 25 Apr 2024 09:04:04 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C30440C6DAE for ; Thu, 25 Apr 2024 09:04:03 +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.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: hlXgcj7pMfu6qgy3GjJvRw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/2] vsh: cmdComplete: Don't leak buffer for completion Date: Thu, 25 Apr 2024 11:04:01 +0200 Message-ID: <843f03215f0d58e51bb731b3e333c4d68869268d.1714035756.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: QZX2JVBUZEX2JVS7TU5KPFL4K4KNOGEZ X-Message-ID-Hash: QZX2JVBUZEX2JVS7TU5KPFL4K4KNOGEZ X-MailFrom: pkrempa@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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1714035921400100001 The buffer which we assign to the 'rl_line_buffer' variable of readline would be overwritten and thus leaked on multiple invocations of cmdComplete in one session. Free/clear it after it's used. Hitting this leak was until recenly possible only in non-interactive batch mode and recently also in interactive mode as 'complete' can be used multiple times now interactively. Fixes: a0e1ada63c0afdc2af3b9405cbf637d8bd28700c Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/vsh.c b/tools/vsh.c index 2805574ec6..05de54b5b0 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3439,7 +3439,10 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd) * In our case it's at the end of the whole line. */ rl_point =3D strlen(rl_line_buffer); - if (!(matches =3D vshReadlineCompletion(arg, 0, 0))) + matches =3D vshReadlineCompletion(arg, 0, 0); + g_clear_pointer(&rl_line_buffer, g_free); + + if (!matches) return false; for (iter =3D matches; *iter; iter++) { --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Sat May 18 18:58:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) 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 1714035962231994.9119925353215; Thu, 25 Apr 2024 02:06:02 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 267E32293; Thu, 25 Apr 2024 05:06:01 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3BDE822B2; Thu, 25 Apr 2024 05:04:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E20871E84; Thu, 25 Apr 2024 05:04:07 -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 83FA21E72 for ; Thu, 25 Apr 2024 05:04:07 -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-148-WeXt7IAzOPm-j00dOXhfSw-1; Thu, 25 Apr 2024 05:04:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 AE7A43803919 for ; Thu, 25 Apr 2024 09:04:05 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 239D240C6CC1 for ; Thu, 25 Apr 2024 09:04:04 +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.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: WeXt7IAzOPm-j00dOXhfSw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/2] vshReadlineInit: Initialize only once Date: Thu, 25 Apr 2024 11:04:02 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: TDD7L3EBDWRN4TFM7UXMOT7RP4BBQHYK X-Message-ID-Hash: TDD7L3EBDWRN4TFM7UXMOT7RP4BBQHYK X-MailFrom: pkrempa@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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1714035963682100001 'vshReadlineInit' is called when interactive virsh is started but also on each call to 'cmdComplete'. Calling it repeatedly (using the 'complete' command interactively, or multiple times in batch mode) leaks the buffers for history file configuration. Avoid multiple setups of this function by returning success in case the history file config is already present. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/vsh.c b/tools/vsh.c index 05de54b5b0..f954f7af77 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2908,6 +2908,10 @@ vshReadlineInit(vshControl *ctl) const char *break_characters =3D " \t\n`@$><=3D;|&{("; const char *quote_characters =3D "\"'"; + /* initialize readline stuff only once */ + if (ctl->historydir) + return 0; + /* Opaque data for autocomplete callbacks. */ autoCompleteOpaque =3D ctl; --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org