aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ospf.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2005-11-15 10:56:18 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2005-11-15 10:56:18 +0000
commit8a88ef70268ceb7c186b15406f4d786f866ed481 (patch)
treef6024a0a120db9f0ce9b730549a3760f0e67949a /epan/dissectors/packet-ospf.c
parentda400db5f1eb3a2702c163d1e0d0b347dcaa4f1a (diff)
Handle OSPF V3 prefixes similarly to the way other IPv6 prefixes are
handled (but not the same, as the prefix length in OSPF is rounded up to a multiple of 4 bytes, not just a byte). This simplifies the code, and keeps us from overflowing the buffer we allocate if the prefix length is > 128 (we now just report that as an error). git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@16507 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/dissectors/packet-ospf.c')
-rw-r--r--epan/dissectors/packet-ospf.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c
index 3833c348ff..34c49d0eaa 100644
--- a/epan/dissectors/packet-ospf.c
+++ b/epan/dissectors/packet-ospf.c
@@ -2496,39 +2496,28 @@ static void dissect_ospf_v3_prefix_options(tvbuff_t *tvb, int offset, proto_tree
static void dissect_ospf_v3_address_prefix(tvbuff_t *tvb, int offset, int prefix_length, proto_tree *tree)
{
- guint8 value;
- guint8 position;
- guint8 bufpos;
- gchar *buffer;
- gchar *bytebuf;
- guint8 bytes_to_process;
- int start_offset;
+ int bytes_to_process;
+ struct e_in6_addr prefix;
- start_offset=offset;
- position=0;
- bufpos=0;
bytes_to_process=((prefix_length+31)/32)*4;
- buffer=ep_alloc(32+7);
- while (bytes_to_process > 0 ) {
-
- value=tvb_get_guint8(tvb, offset);
-
- if ( (position > 0) && ( (position%2) == 0 ) )
- buffer[bufpos++]=':';
-
- bytebuf=ep_alloc(3);
- g_snprintf(bytebuf, 3, "%02x",value);
- buffer[bufpos++]=bytebuf[0];
- buffer[bufpos++]=bytebuf[1];
-
- position++;
- offset++;
- bytes_to_process--;
+ if (prefix_length > 128) {
+ proto_tree_add_text(tree, tvb, offset, bytes_to_process,
+ "Address Prefix: length is invalid (%d, should be <= 128)",
+ prefix_length);
+ return;
}
- buffer[bufpos]=0;
- proto_tree_add_text(tree, tvb, start_offset, ((prefix_length+31)/32)*4, "Address Prefix: %s",buffer);
+ memset(prefix.bytes, 0, sizeof prefix.bytes);
+ if (bytes_to_process != 0) {
+ tvb_memcpy(tvb, prefix.bytes, offset, bytes_to_process);
+ if (prefix_length % 8) {
+ prefix.bytes[bytes_to_process - 1] &=
+ ((0xff00 >> (prefix_length % 8)) & 0xff);
+ }
+ }
+ proto_tree_add_text(tree, tvb, offset, bytes_to_process,
+ "Address Prefix: %s", ip6_to_str(&prefix));
}