From nobody Tue Mar 3 03:02:46 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; 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1771957663; cv=none; d=zohomail.com; s=zohoarc; b=PiA5c/eocc02mWPxlJylrHO6mW/ZamH+e/cxd5KxOjyJsiwituQ2jaYOjJxZ8g92owyAIPn73J4enLUBXmUtuH34cic4RucnibMOdmCHvzkROSFBzwUYgnWPNVi7fFaCboyiGkyLhzRJZwCvDqChBkye9F59M1kdKsjyt87UhNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771957663; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=T86wAXkF605FlcRF6/y7Ma6zSXMB7XDMGKROWvdhGcI=; b=ReNxE2DTBUHX+wRqN+lK7uLmzkYTx9Gf+IhU/OTNAFixf3r5SovmFZUeKLHKcjrYivZNOgfVMs2ypGfh5g4dcJxIYT01g+Ylom2XOICSZB/rkc+ImDhvow+Z4PyNxVPyRH6zJWk0HBtWEhl4BEQ8hoyJT2PfSIjl3MBzv9VeYvE= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1771957663657690.2344020874178; Tue, 24 Feb 2026 10:27:43 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id AFC1641CC0; Tue, 24 Feb 2026 13:27:42 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1947141D2A; Tue, 24 Feb 2026 13:26:20 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 54F184189E; Tue, 24 Feb 2026 13:26:15 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D532241B68 for ; Tue, 24 Feb 2026 13:26:14 -0500 (EST) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-JavXhZryO-yc5e-aSKr-9A-1; Tue, 24 Feb 2026 13:26:12 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 02F0E1955D70; Tue, 24 Feb 2026 18:26:11 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.225.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5FD4D3003D99; Tue, 24 Feb 2026 18:26:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771957574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T86wAXkF605FlcRF6/y7Ma6zSXMB7XDMGKROWvdhGcI=; b=B7+66AgTVZvroRHbE0qcm3i8akHnKE084TyZ91EbCEPmc5Vu3bg7n5pPpbHL2951g+dqrA G5J4c8E6/y4vUIxcveQ1beryLeL/0FsAKj14Vml2oWL/W1+ij7ad9qzCBgiETk8/hF3a1R VZUD7wkmJ6ZtQ8zP6WGTNaiIDadqrAA= X-MC-Unique: JavXhZryO-yc5e-aSKr-9A-1 X-Mimecast-MFC-AGG-ID: JavXhZryO-yc5e-aSKr-9A_1771957571 To: devel@lists.libvirt.org Subject: [PATCH 1/2] fdstream: don't set return value if looping to read more data Date: Tue, 24 Feb 2026 18:26:03 +0000 Message-ID: <20260224182604.309069-2-berrange@redhat.com> In-Reply-To: <20260224182604.309069-1-berrange@redhat.com> References: <20260224182604.309069-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vWcyC6cmDtzhCvrtaKB2Uls0uyBeorvU-B3tKtSE3Xo_1771957571 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TLWPTUXXZCQLJPLUPNNIRCVCGZANB6RM X-Message-ID-Hash: TLWPTUXXZCQLJPLUPNNIRCVCGZANB6RM X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Erik Huelsmann , Roman Bogorodskiy X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771957664693158500 From: Daniel P. Berrang=C3=A9 The 'ret' variable should only have a value assigned once we have completely finished reading data, otherwise an error on a subsequent iteration will report an error but not return a negative value. Fixes: e23fd0b7fd36c41e6db49df4f4962762d3ef6ab0 Reported-by: Roman Bogorodskiy Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina Tested-by: Roman Bogorodskiy --- src/util/virfdstream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 4c974ba5d7..cd2ede4501 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -961,10 +961,10 @@ static int virFDStreamRead(virStreamPtr st, char *byt= es, size_t nbytes) virFDStreamMsgFree(msg); } =20 - ret =3D got; if (nbytes > 0) { goto more; } + ret =3D got; } else { retry: ret =3D read(fdst->fd, bytes, nbytes); --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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; 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1771957705; cv=none; d=zohomail.com; s=zohoarc; b=oBmZW1EG669tos3a9qpsQertBf/7vwqJmbc7wjNgHE2tF3ZQIHu5YdcaIzP0M5ny26XlCaExo6AL7Kx1+U3qXc0JYFLjDx0coSVw+wLkmIXt0s9gtOG6IkPrZ8WmBcjxkdmvvpEhuBvxfpDLjoLIUqKP1QyXCxIM1sFKXHUJoSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771957705; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=Q+xAqX+zY/1QE/ycA9YIBAzS4lIQ8U9/gsXcnnaESfQ=; b=bthj4/pLn5kMb5PRXJeD00qVlMaF3GMbM279iA2ho3j3msUKy6Iem29fEiy2Use0CGQAhk115GQPdRB/NdViekpbnKt4/e1IZ52K0ODiAIE/+hjoPWErsNpuuzTklJCo/bp0jKGfQ1F+Mgz61pvvvG6Crx3lM2oyKhfpsvFigrc= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 177195770508385.67796469322809; Tue, 24 Feb 2026 10:28:25 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1C7A241B87; Tue, 24 Feb 2026 13:28:24 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 67AA641D43; Tue, 24 Feb 2026 13:27:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3D24C41D3F; Tue, 24 Feb 2026 13:27:02 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0BCA841D69 for ; Tue, 24 Feb 2026 13:26:19 -0500 (EST) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-EM9ga5RkO5qfILirsqNU1A-1; Tue, 24 Feb 2026 13:26:15 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E492A1956068; Tue, 24 Feb 2026 18:26:12 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.225.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 71E323000707; Tue, 24 Feb 2026 18:26:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771957578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q+xAqX+zY/1QE/ycA9YIBAzS4lIQ8U9/gsXcnnaESfQ=; b=J24T0ZqFgIhguH5FWtrfqBsmULZZV7t2WM9olBTX3dXRlAFWkIKcFszDnevb8GGy8kSNNy 0HLw/K5ke0wSeXyfcWjo8Xpu2ejW6UAQzomPpOppW//KxMoJ1pt9ZETIBULNm7QdnD5pqc /L7djrxq/Bo9CXX0KRz7+GWuJD7i4Oo= X-MC-Unique: EM9ga5RkO5qfILirsqNU1A-1 X-Mimecast-MFC-AGG-ID: EM9ga5RkO5qfILirsqNU1A_1771957574 To: devel@lists.libvirt.org Subject: [PATCH 2/2] fdstream: fix EOF handling when reading data Date: Tue, 24 Feb 2026 18:26:04 +0000 Message-ID: <20260224182604.309069-3-berrange@redhat.com> In-Reply-To: <20260224182604.309069-1-berrange@redhat.com> References: <20260224182604.309069-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 9jimwkPV3Ul7xpscNCZu2OR-_nq-wTGpj5BzWfxj5-M_1771957574 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MKLL73VOPOZNLKNECJ2XFH74JZR277WM X-Message-ID-Hash: MKLL73VOPOZNLKNECJ2XFH74JZR277WM X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Erik Huelsmann , Roman Bogorodskiy X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771957707055158500 From: Daniel P. Berrang=C3=A9 A recent commit caused the virFDStreamRead method to loop reading data until the provided buffer is full. Unfortunately the EOF handling was not quiet correct. * When seeing a virFDStreamMsg with length zero, it would still loop trying to read more and then get an error that the thread has quit. * When seeing a virFDStreamMsg with length zero on subsequent iterations, it would discard this message, which would in turn prevent the caller from ever seeing the 'ret =3D=3D 0' return value indicating EOF. The caller would then try to read again and get an error about the stream being closed. Fixes: e23fd0b7fd36c41e6db49df4f4962762d3ef6ab0 Reported-by: Roman Bogorodskiy Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina Tested-by: Roman Bogorodskiy --- src/util/virfdstream.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index cd2ede4501..9fe70be0b9 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -907,6 +907,7 @@ static int virFDStreamRead(virStreamPtr st, char *bytes= , size_t nbytes) virFDStreamMsg *msg =3D NULL; size_t got =3D 0; size_t bsz =3D 0; + bool isEOF; =20 more: while (!(msg =3D fdst->msg)) { @@ -945,6 +946,7 @@ static int virFDStreamRead(virStreamPtr st, char *bytes= , size_t nbytes) goto cleanup; } =20 + isEOF =3D msg->stream.data.len =3D=3D 0; bsz =3D msg->stream.data.len - msg->stream.data.offset; if (nbytes < bsz) bsz =3D nbytes; @@ -956,12 +958,24 @@ static int virFDStreamRead(virStreamPtr st, char *byt= es, size_t nbytes) nbytes -=3D bsz; =20 msg->stream.data.offset +=3D bsz; - if (msg->stream.data.offset =3D=3D msg->stream.data.len) { + /* If we stream msg is fully consumed, then remove + * it from the queue. + * + * Exception: if this is the second time around the + * loop, and the msg indicated an EOF, we must leave + * it on the queue so a subsequent read sees the + * ret =3D=3D 0 EOF condition + */ + if (msg->stream.data.offset =3D=3D msg->stream.data.len && + (!isEOF || got =3D=3D 0)) { virFDStreamMsgQueuePop(fdst, fdst->fd, "pipe"); virFDStreamMsgFree(msg); } =20 - if (nbytes > 0) { + /* If we didn't just see EOF and can read more into + * 'bytes' then retry the loop + */ + if (nbytes > 0 && !isEOF) { goto more; } ret =3D got; --=20 2.53.0