From nobody Mon Feb 9 01:22:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1653476523; cv=none; d=zohomail.com; s=zohoarc; b=ksbFEXVnVz1PqH/O7jVJ92/mnUmAT0LSLd3gbKkPADGCo8ozWQTkSk7pUOrY9qpI8goxo+1iUETSSVLF6S+18SFH+3Q9v43Vvw718RD4MRb5qdUCiBxrgKqiBjMwKgMma2d26quHZEXpAD7zbwSnwGy+9xtOD9ZD3scl37Mq368= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653476523; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ffwG5TrHBMuvE0e62P64PsUuPrhFPSplpWBoK44Ics8=; b=JLzaUXvZ+DZH9A8rxy2uOOp3Is+GWFoJk/m+TJi6ufYeJSsDWKbabBNHrV4EVaCyJ4G20TQyUxdTIyycjdaDZjbqHF2IrG3E3uOAjTBhov4OMtyRwCJq1ktt20n3mm87daKnw1OEOOeSFFwNTd2ITp5uPXqth1K8kLCQUhVhDJg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1653476523825104.55755952577113; Wed, 25 May 2022 04:02:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-551-QxmsEAr_PGi9E0O320eJ6Q-1; Wed, 25 May 2022 07:01:17 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5C308041B3; Wed, 25 May 2022 11:01:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB161401E63; Wed, 25 May 2022 11:01:13 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9CA1F1932127; Wed, 25 May 2022 11:01:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 62662194EB82 for ; Wed, 25 May 2022 11:01:11 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 438A6C23DC1; Wed, 25 May 2022 11:01:11 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEC46C15E71 for ; Wed, 25 May 2022 11:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653476522; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ffwG5TrHBMuvE0e62P64PsUuPrhFPSplpWBoK44Ics8=; b=ZrLJmOXJdYcwuLEqbFu/nbWdqh+RPfeAbKdWjwi5Pq2Ey6MqxuOqx6TBVkK7DpqPPU8RjI XlK6lYzt9cGwRyu/iQxzApKyRQ1oR0GN/CoHARUaSeyj14esdEMj+IiVjw0YOXkXz4SG/L RqYDMo9kGVI5eM/zpQLcfL8+HNpTTG4= X-MC-Unique: QxmsEAr_PGi9E0O320eJ6Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] virNetMessageEncodePayloadRaw: Tolerate empty 'data' Date: Wed, 25 May 2022 13:01:07 +0200 Message-Id: <17daeb4cefd7b119a0c734fef1ea78ee880462a1.1653476354.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1653476524303100001 Content-Type: text/plain; charset="utf-8" 'virNetMessageEncodePayloadRaw' is not supposed to be called with 'NULL' data, but the code path from 'virNetClientStreamSendPacket' does so. Now 'virNetMessageEncodePayloadEmpty' is intended for such case, but since it's just a sub-set of steps from 'virNetMessageEncodePayloadRaw' it's more straightforward to add NULL-tolerance to 'virNetMessageEncodePayl= oadRaw' and subsequently remove 'virNetMessageEncodePayloadEmpty'. Closes: https://gitlab.com/libvirt/libvirt/-/issues/308 Signed-off-by: Peter Krempa --- src/rpc/virnetmessage.c | 51 +++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 221da7c59b..b806adf782 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -434,6 +434,15 @@ int virNetMessageDecodePayload(virNetMessage *msg, } +/** + * virNetMessageEncodePayloadRaw: + * @msg: message to encode payload into + * @data: data to encode into @msg + * @len: lenght of @data + * + * Encodes message payload. If @data is NULL or @len is 0 an empty message= is + * encoded. + */ int virNetMessageEncodePayloadRaw(virNetMessage *msg, const char *data, size_t len) @@ -441,30 +450,32 @@ int virNetMessageEncodePayloadRaw(virNetMessage *msg, XDR xdr; unsigned int msglen; - /* If the message buffer is too small for the payload increase it acco= rdingly. */ - if ((msg->bufferLength - msg->bufferOffset) < len) { - if ((msg->bufferOffset + len) > - (VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX)) { - virReportError(VIR_ERR_RPC, - _("Stream data too long to send " - "(%zu bytes needed, %zu bytes available)"), - len, - VIR_NET_MESSAGE_MAX + - VIR_NET_MESSAGE_LEN_MAX - - msg->bufferOffset); - return -1; + if (data && len > 0) { + /* If the message buffer is too small for the payload increase it = accordingly. */ + if ((msg->bufferLength - msg->bufferOffset) < len) { + if ((msg->bufferOffset + len) > + (VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX)) { + virReportError(VIR_ERR_RPC, + _("Stream data too long to send " + "(%zu bytes needed, %zu bytes available)"= ), + len, + VIR_NET_MESSAGE_MAX + + VIR_NET_MESSAGE_LEN_MAX - + msg->bufferOffset); + return -1; + } + + msg->bufferLength =3D msg->bufferOffset + len; + + VIR_REALLOC_N(msg->buffer, msg->bufferLength); + + VIR_DEBUG("Increased message buffer length =3D %zu", msg->buff= erLength); } - msg->bufferLength =3D msg->bufferOffset + len; - - VIR_REALLOC_N(msg->buffer, msg->bufferLength); - - VIR_DEBUG("Increased message buffer length =3D %zu", msg->bufferLe= ngth); + memcpy(msg->buffer + msg->bufferOffset, data, len); + msg->bufferOffset +=3D len; } - memcpy(msg->buffer + msg->bufferOffset, data, len); - msg->bufferOffset +=3D len; - /* Re-encode the length word. */ VIR_DEBUG("Encode length as %zu", msg->bufferOffset); xdrmem_create(&xdr, msg->buffer, VIR_NET_MESSAGE_HEADER_XDR_LEN, XDR_E= NCODE); --=20 2.35.3