From nobody Sat Apr 27 10:32:52 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=1638182292; cv=none; d=zohomail.com; s=zohoarc; b=TpUzso/NhwLrRrrjbqWRKfhewxj44YeViplPKCmSNaCj5aK8zlpszkW27BmDqyLVHnv3R17ZyANJMYMDf7/xxFhPzb5C6OZRLrAXoUHP4g2b7SyGC1VIrSD25FR069EQacdf5TkDLUMzSZ4nY+nDuoYNbN0Fr/H9lxRUFzVkFc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638182292; 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=uCLc3XnnpeMDgu3+NLdmdWVLjGmQ4/OVgikPUIgT4hY=; b=ikXCkWueeWdtOB2/TrdhCUp75RwgHKYWe8T7on9/70vqoGVsFnpJC7mOtM0ItElzCp1wLWKYlkkfXVFtTMfXygy4IEbDMubypYfHggU4A8T+H5PPWwVp0zWEYnh8QRofBdDBtqPfU/aBs7QePdG8Jf7aj78pxLWhc5/tSsOATKI= 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 1638182292110108.97297309026362; Mon, 29 Nov 2021 02:38:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-QbCC7lZxP5KFTysisle5Jw-1; Mon, 29 Nov 2021 05:38:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DFC51835E26; Mon, 29 Nov 2021 10:38:02 +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 C212A19724; Mon, 29 Nov 2021 10:38:02 +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 8903A4BB7C; Mon, 29 Nov 2021 10:38:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ATAZwxn013878 for ; Mon, 29 Nov 2021 05:35:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B9CA319741; Mon, 29 Nov 2021 10:35:58 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 432ED196E5 for ; Mon, 29 Nov 2021 10:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638182291; 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=uCLc3XnnpeMDgu3+NLdmdWVLjGmQ4/OVgikPUIgT4hY=; b=EuXfUH8ct6fs00IiCmH+TGAq3xmRPwSYDL18D/cnQuyT8J4U1IcFkdTJl5BRyNkrkwskz9 UqREpWHT6Bl9i42eJUMU0YodRdd1YLAUhuohRnWQlxiFaEdALEDRSXNJEyHs7RCQSf5llZ gpWcCoJCK7k0uPVlpOYClvcqMWEH3Zk= X-MC-Unique: QbCC7lZxP5KFTysisle5Jw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] wireshark: Switch to tvb_bytes_to_str() Date: Mon, 29 Nov 2021 11:35:49 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: 1638182293871100001 Content-Type: text/plain; charset="utf-8" When the dissector sees a byte sequence that is either an opaque data (xdr_opaque) or a byte sequence (xdr_bytes) it formats the bytes as a hex numbers using our own implementation. But wireshark already provides a function for it: tvb_bytes_to_str(). NB, the reason why it returns a const string is so that callers don't try to free it - the string is allocated using an allocator which will decide when to free it. The wireshark formatter was introduced in wireshark commit of v1.99.2~479 and thus is present in the version we require at least (2.6.0). Signed-off-by: Michal Privoznik --- tools/wireshark/src/packet-libvirt.c | 30 ++++++++-------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/pac= ket-libvirt.c index f43919b05d..cb922b8070 100644 --- a/tools/wireshark/src/packet-libvirt.c +++ b/tools/wireshark/src/packet-libvirt.c @@ -158,24 +158,6 @@ dissect_xdr_string(tvbuff_t *tvb, proto_tree *tree, XD= R *xdrs, int hf, } } =20 -static const gchar * -format_xdr_bytes(guint8 *bytes, guint32 length) -{ - gchar *buf; - guint32 i; - - if (length =3D=3D 0) - return ""; - buf =3D wmem_alloc(wmem_packet_scope(), length*2 + 1); - for (i =3D 0; i < length; i++) { - /* We know that buf has enough size to contain - 2 * length + '\0' characters. */ - g_snprintf(buf, 2*(length - i) + 1, "%02x", bytes[i]); - buf +=3D 2; - } - return buf - length*2; -} - static gboolean dissect_xdr_opaque(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, guint32 size) @@ -187,8 +169,10 @@ dissect_xdr_opaque(tvbuff_t *tvb, proto_tree *tree, XD= R *xdrs, int hf, val =3D g_malloc(size); start =3D xdr_getpos(xdrs); if ((rc =3D xdr_opaque(xdrs, (caddr_t)val, size))) { - proto_tree_add_bytes_format_value(tree, hf, tvb, start, xdr_getpos= (xdrs) - start, - NULL, "%s", format_xdr_bytes(val= , size)); + gint len =3D xdr_getpos(xdrs) - start; + const char *s =3D tvb_bytes_to_str(wmem_packet_scope(), tvb, start= , len); + + proto_tree_add_bytes_format_value(tree, hf, tvb, start, len, NULL,= "%s", s); } else { proto_tree_add_item(tree, hf_libvirt_unknown, tvb, start, -1, ENC_= NA); } @@ -207,8 +191,10 @@ dissect_xdr_bytes(tvbuff_t *tvb, proto_tree *tree, XDR= *xdrs, int hf, =20 start =3D xdr_getpos(xdrs); if (xdr_bytes(xdrs, (char **)&val, &length, maxlen)) { - proto_tree_add_bytes_format_value(tree, hf, tvb, start, xdr_getpos= (xdrs) - start, - NULL, "%s", format_xdr_bytes(val= , length)); + gint len =3D xdr_getpos(xdrs) - start; + const char *s =3D tvb_bytes_to_str(wmem_packet_scope(), tvb, start= , len); + + proto_tree_add_bytes_format_value(tree, hf, tvb, start, len, NULL,= "%s", s); /* Seems I can't call xdr_free() for this case. It will raises SEGV by referencing out of bounds call stack */ free(val); --=20 2.32.0 From nobody Sat Apr 27 10:32:52 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=1638182243; cv=none; d=zohomail.com; s=zohoarc; b=HASKEHJwHaKbxP8YcyOytpXMorbOv0RLdPjWHJqn4mFc6LvjHGXTXd6qwPa3RsF4L8Pr3FrYuwNcCuSJnWVI6Ls0jeoA0b/Q4cE7aChYZSa4hjSBCVt7nSm3MHk71fSUuMED6xyC2A6TvDKy23HrJ22PdPRArJmogOnxvTe3Dl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638182243; 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=lc9ezkL9LIrmMIQghjMVPRgVDy8HonhQ2UcLzUnknrU=; b=Ww+1PiVAhcjaIds1vsnjLjv8ozb02laV1xxdiIm1zQd0W78C0JTDu8quLmY+atjtiHun7hoZA8sst3wwFsZ3h5s4KXooKmW4kcNpCzlJg5jmyj5dImz9r8y8Srr1KkAOw5/a/R77QFEk9KpDNHUhxnJTKHx56ueEXXJDV+lk0ts= 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 1638182243088779.6183826423116; Mon, 29 Nov 2021 02:37:23 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-cobSY7FjP9qsvf2AQJIVYQ-1; Mon, 29 Nov 2021 05:37:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B48E2835E22; Mon, 29 Nov 2021 10:37:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 578CB10023B8; Mon, 29 Nov 2021 10:37:13 +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 4F20B1809CB8; Mon, 29 Nov 2021 10:37:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ATAZxhi013883 for ; Mon, 29 Nov 2021 05:35:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8A446196E5; Mon, 29 Nov 2021 10:35:59 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1364319741 for ; Mon, 29 Nov 2021 10:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638182242; 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=lc9ezkL9LIrmMIQghjMVPRgVDy8HonhQ2UcLzUnknrU=; b=e3QUIiKgF9fSDOkVuTrSwfVuYeYnUBQ2PREqTXAfwrCWdZ0tUDVxuiJ5tp6RT1jQ6ZlG0O 3G0UUMMJAow8ywjblAT66rGY+VgWdrLaV6o57bTTIBaaZ1DpoGxzIcl79nb1bDQp4ClIZr vAz4QgQv6ofg0vetep/bZV5dPsV+ivc= X-MC-Unique: cobSY7FjP9qsvf2AQJIVYQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] wireshark: Drop needless comment in dissect_xdr_bytes() Date: Mon, 29 Nov 2021 11:35:50 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: 1638182245191100001 Content-Type: text/plain; charset="utf-8" In the dissect_xdr_bytes() there's a comment that the string allocated by xdr_bytes() can't be freed using xdr_free(). Well, that is expected because xdr_bytes() used plain calloc() AND the string is not an XDR struct but plain 'char *' type. Passing it to xdr_free() must result in weird things happening. Signed-off-by: Michal Privoznik --- tools/wireshark/src/packet-libvirt.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/pac= ket-libvirt.c index cb922b8070..eeacbcdf0e 100644 --- a/tools/wireshark/src/packet-libvirt.c +++ b/tools/wireshark/src/packet-libvirt.c @@ -195,8 +195,6 @@ dissect_xdr_bytes(tvbuff_t *tvb, proto_tree *tree, XDR = *xdrs, int hf, const char *s =3D tvb_bytes_to_str(wmem_packet_scope(), tvb, start= , len); =20 proto_tree_add_bytes_format_value(tree, hf, tvb, start, len, NULL,= "%s", s); - /* Seems I can't call xdr_free() for this case. - It will raises SEGV by referencing out of bounds call stack */ free(val); return TRUE; } else { --=20 2.32.0