From nobody Sat Feb 7 23:58:21 2026 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; 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 1715170372279660.894593786546; Wed, 8 May 2024 05:12:52 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 33B841DC9; Wed, 8 May 2024 08:12:51 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8BCC51BE8; Wed, 8 May 2024 08:11:44 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 74C061A12; Wed, 8 May 2024 08:11:38 -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 6E1F11BBF for ; Wed, 8 May 2024 08:11:36 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-GQqbeEndO9OhFRgLmQHXdQ-1; Wed, 08 May 2024 08:11:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 B63BF8016FA for ; Wed, 8 May 2024 12:11:34 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 230111004C62; Wed, 8 May 2024 12:11:34 +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: GQqbeEndO9OhFRgLmQHXdQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Subject: [PATCH 2/2] tests: fix two off-by-1 errors in read-big-pipe test Date: Wed, 8 May 2024 13:11:31 +0100 Message-ID: <20240508121131.1214941-3-berrange@redhat.com> In-Reply-To: <20240508121131.1214941-1-berrange@redhat.com> References: <20240508121131.1214941-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: XUSZ57CZJVR6ZTJIYZ4677QCGSJHSMLV X-Message-ID-Hash: XUSZ57CZJVR6ZTJIYZ4677QCGSJHSMLV X-MailFrom: berrange@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 CC: Andrea Bolognani , Peter Krempa 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: 1715170373967100001 When testPipeFeeder copies the XML document into the padded buffer, it tells virStrcpy that 'xmlsize' bytes are available. This is under reporting size by 1 byte, and as a result it fails to copy the trailing '\n' replacing it when '\0'. The return value of virStrcpy wasn't checked, but was reporting this truncation. When testPipeFeeder then sends the padded buffer down the pipe, it askes to send 'emptyspace + xmlsize + 1' bytes, which means it sends the data, as well as the trailing '\0' terminator. Both bugs combined mean it is sending '\0\0' as the last bytes, instead of '\n' which was intended. When virFileReadAll reads data from the pipe, it ends up adding another '\0' resulting in in a very NUL terminated string ('\0\0\0'). This is all harmless, but should be fixed regardless. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Andrea Bolognani --- tests/virshtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 7a7797647c..03d499b759 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -151,9 +151,9 @@ testPipeFeeder(void *opaque) } =20 memset(doc, ' ', emptyspace); - virStrcpy(doc + emptyspace, xml, xmlsize); + g_assert(virStrcpy(doc + emptyspace, xml, xmlsize + 1) =3D=3D 0); =20 - if (safewrite(fd, doc, emptyspace + xmlsize + 1) < 0) { + if (safewrite(fd, doc, emptyspace + xmlsize) < 0) { fprintf(stderr, "\nfailed to write to pipe '%s': %s\n", pipepath, = g_strerror(errno)); return; } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org