From nobody Fri May 3 20:44:48 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496667217464391.5569483984383; Mon, 5 Jun 2017 05:53:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B21CF83F47; Mon, 5 Jun 2017 12:53:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FE5F83079; Mon, 5 Jun 2017 12:53:35 +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 160B74BB7F; Mon, 5 Jun 2017 12:53:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v55CrXjL028435 for ; Mon, 5 Jun 2017 08:53:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6DDE48E90F; Mon, 5 Jun 2017 12:53:33 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-112.brq.redhat.com [10.40.204.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4A2B8E904 for ; Mon, 5 Jun 2017 12:53:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B21CF83F47 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B21CF83F47 From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 14:53:19 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virFDStreamThread: Make sure we won't exceed @length 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 05 Jun 2017 12:53:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There's a problem with current streams after I switched them from iohelper to thread implementation. Previously, iohelper made sure not to exceed specified @length resulting in the pipe EOF appearing at the exact right moment (the pipe was used to tunnel the data from the iohelper to the daemon). Anyway, when switching to thread I had to write the I/O code from scratch. Whilst doing that I took an inspiration from the iohelper code, but since the usage of pipe switched to slightly different meaning, there was no 1:1 relationship between the codes. Moreover, after introducing VIR_FDSTREAM_MSG_TYPE_HOLE, the condition that should made sure we won't exceed @length was completely wrong. The fix is to: a) account for holes for @length b) cap not just data sections but holes too (if @length would be exceeded) For this purpose, the condition needs to be brought closer to the code that handles holes and data sections. Signed-off-by: Michal Privoznik --- src/util/virfdstream.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 7ee58be13..ae6f78e01 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -420,6 +420,8 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst, const int fdout, const char *fdinname, const char *fdoutname, + size_t length, + size_t total, size_t *dataLen, size_t buflen) { @@ -433,10 +435,18 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst, if (virFileInData(fdin, &inData, §ionLen) < 0) goto error; =20 + if (length && + sectionLen > length - total) + sectionLen =3D length - total; + if (inData) *dataLen =3D sectionLen; } =20 + if (length && + buflen > length - total) + buflen =3D length - total; + if (VIR_ALLOC(msg) < 0) goto error; =20 @@ -578,13 +588,6 @@ virFDStreamThread(void *opaque) while (1) { ssize_t got; =20 - if (length && - (length - total) < buflen) - buflen =3D length - total; - - if (buflen =3D=3D 0) - break; /* End of requested data from client */ - while (doRead =3D=3D (fdst->msg !=3D NULL) && !fdst->threadQuit) { if (virCondWait(&fdst->threadCond, &fdst->parent.lock)) { @@ -608,6 +611,7 @@ virFDStreamThread(void *opaque) got =3D virFDStreamThreadDoRead(fdst, sparse, fdin, fdout, fdinname, fdoutname, + length, total, &dataLen, buflen); else got =3D virFDStreamThreadDoWrite(fdst, sparse, --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list