From nobody Sat May 11 08:39:33 2024 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 Reviewed-by: Claudio Fontana Reviewed-by: Michal Privoznik --- 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 From nobody Sat May 11 08:39:33 2024 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=1653476524; cv=none; d=zohomail.com; s=zohoarc; b=e0C1a6rqD+VJWm7abNEC61C8KwsfptVscYonnfSVZbLNb/CvBBv61ZfdfCiH8WjRmUz7c410c+Y0JLJK+Ow8Lxf4A/xyhFBiYZ6MWIyQatwFVbo/Pdxs25KWIyoJUzEqf/ZyU3VNRVrzWM2vIe0d1GORSsV3Eb+XVNMOYEoVUMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653476524; 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=sPtU4kElUT6oHCjcz7xWK9BbNZ2vtkbNmwWliB7hYGY=; b=jH74iTva+tZnvZU1c2lCYvM7Z5TehjGItQXv5IeMJzWo4sgbOdJ4/PG5mDjVRJXRShsEMFUFIJR8kBnokjkmuxxo0h3ep/qCGM7Bb4Q+hqePMW6MEfz2vdwzNwkjTVui0+kDa8AX34X7/U+i5p6IjQqKSXV/PzlY1/NvdWM643M= 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 1653476524389209.1786177091319; Wed, 25 May 2022 04:02:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-6c3UqTC1MiK4iTYFENTciw-1; Wed, 25 May 2022 07:01:17 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C52B33817A95; 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 6C3DE492C3B; Wed, 25 May 2022 11:01:14 +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 E0BF3194EB88; Wed, 25 May 2022 11:01:13 +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 30AAE194F4BF for ; Wed, 25 May 2022 11:01:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 18BAFC27E92; Wed, 25 May 2022 11:01:12 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90761C23DC1 for ; Wed, 25 May 2022 11:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653476523; 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=sPtU4kElUT6oHCjcz7xWK9BbNZ2vtkbNmwWliB7hYGY=; b=b/gykv8nYM9Sd8NFNouT9D/0LR4KQu0B+7z1r+F+nKAgvvW6Q4fzUKPrK9/DNgWxnkvIRE dtRDvZwlYTWBttkMvek5ZTg8biEQFXQqeje/wdwCuxT7YQqS+Fd6V4iHgxXe54qzSORCbL pSVfYe4pYxN2DlezeCe0RplVYur+Q+o= X-MC-Unique: 6c3UqTC1MiK4iTYFENTciw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/2] virNetMessageEncodePayloadEmpty: Replace by virNetMessageEncodePayloadRaw(msg, NULL, 0) Date: Wed, 25 May 2022 13:01:08 +0200 Message-Id: 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.9 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: 1653476526316100003 Content-Type: text/plain; charset="utf-8" Replace the two outstanding invocations and remove the function. Signed-off-by: Peter Krempa Reviewed-by: Claudio Fontana Reviewed-by: Michal Privoznik --- src/rpc/virkeepalive.c | 2 +- src/rpc/virnetmessage.c | 25 ------------------------- src/rpc/virnetmessage.h | 2 -- src/rpc/virnetserverprogram.c | 9 ++------- 4 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c index 9d08c3bcca..52decf5a5f 100644 --- a/src/rpc/virkeepalive.c +++ b/src/rpc/virkeepalive.c @@ -91,7 +91,7 @@ virKeepAliveMessage(virKeepAlive *ka, int proc) msg->header.proc =3D proc; if (virNetMessageEncodeHeader(msg) < 0 || - virNetMessageEncodePayloadEmpty(msg) < 0) { + virNetMessageEncodePayloadRaw(msg, NULL, 0) < 0) { virNetMessageFree(msg); goto error; } diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index b806adf782..d78438bd95 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -496,31 +496,6 @@ int virNetMessageEncodePayloadRaw(virNetMessage *msg, } -int virNetMessageEncodePayloadEmpty(virNetMessage *msg) -{ - XDR xdr; - unsigned int msglen; - - /* 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); - msglen =3D msg->bufferOffset; - if (!xdr_u_int(&xdr, &msglen)) { - virReportError(VIR_ERR_RPC, "%s", _("Unable to encode message leng= th")); - goto error; - } - xdr_destroy(&xdr); - - msg->bufferLength =3D msg->bufferOffset; - msg->bufferOffset =3D 0; - return 0; - - error: - xdr_destroy(&xdr); - return -1; -} - - void virNetMessageSaveError(struct virNetMessageError *rerr) { virErrorPtr verr; diff --git a/src/rpc/virnetmessage.h b/src/rpc/virnetmessage.h index 8f878962f8..849674fa53 100644 --- a/src/rpc/virnetmessage.h +++ b/src/rpc/virnetmessage.h @@ -85,8 +85,6 @@ int virNetMessageEncodePayloadRaw(virNetMessage *msg, const char *buf, size_t len) ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; -int virNetMessageEncodePayloadEmpty(virNetMessage *msg) - ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; void virNetMessageSaveError(struct virNetMessageError *rerr) ATTRIBUTE_NONNULL(1); diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 070d76fdd0..3ddf9f0428 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -518,14 +518,9 @@ int virNetServerProgramSendStreamData(virNetServerProg= ram *prog, if (virNetMessageEncodeHeader(msg) < 0) return -1; - if (data && len) { - if (virNetMessageEncodePayloadRaw(msg, data, len) < 0) - return -1; + if (virNetMessageEncodePayloadRaw(msg, data, len) < 0) + return -1; - } else { - if (virNetMessageEncodePayloadEmpty(msg) < 0) - return -1; - } VIR_DEBUG("Total %zu", msg->bufferLength); return virNetServerClientSendMessage(client, msg); --=20 2.35.3