Wireshark-dev: [Wireshark-dev] [PATCH] BGP: simplify check of labeled prefix length

From: Vitaliy Guschin <guschin108@xxxxxxxxx>
Date: Tue, 6 Aug 2024 04:46:38 +0700
Hi,

From 0271a9b937c3a0d785bfbc6524f5f6997bf5af5e Mon Sep 17 00:00:00 2001
From: Vitaliy Guschin <guschin108@xxxxxxxxx>
Date: Fri, 5 Aug 2024 02:06:41 +0700
Subject: [PATCH] BGP: simplify check of labeled prefix length

Simplified validation and removed redundancy.
---
 epan/dissectors/packet-bgp.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/epan/dissectors/packet-bgp.c b/epan/dissectors/packet-bgp.c
index 7ac475afaf..fe4899f8ec 100644
--- a/epan/dissectors/packet-bgp.c
+++ b/epan/dissectors/packet-bgp.c
@@ -7609,15 +7609,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
                                         tag, plen);
                     return -1;
                 }
-                plen -= (labnum * 3*8);
-
-                if (plen < 8*8) {
-                    proto_tree_add_expert_format(tree, pinfo, &ei_bgp_prefix_length_invalid, tvb, start_offset, 1, -                                        "%s Labeled VPN IPv4 prefix length %u invalid",
-                                        tag, plen + (labnum * 3*8));
-                    return -1;
-                }
-                plen -= 8*8;
+                plen -= (labnum * 3*8 + 8*8);

                 length = tvb_get_ipv4_addr_with_prefix_len(tvb, offset + 8, &ip4addr, plen);
                 if (length < 0) {
@@ -7807,15 +7799,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,                                          "%s Labeled VPN IPv6 prefix length %u invalid", tag, plen);
                     return -1;
                 }
-                plen -= (labnum * 3*8);
-
-                if (plen < 8*8) {
-                    proto_tree_add_expert_format(tree, pinfo, &ei_bgp_prefix_length_invalid, tvb, start_offset, 1, -                                        "%s Labeled VPN IPv6 prefix length %u invalid",
-                                        tag, plen + (labnum * 3*8));
-                    return -1;
-                }
-                plen -= 8*8;
+                plen -= (labnum * 3*8 + 8*8);

                 length = tvb_get_ipv6_addr_with_prefix_len(tvb, offset + 8, &ip6addr, plen);
                 if (length < 0) {
--
2.46.0

Best regards,
Vitaliy.