diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-02-25 09:31:07 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-02-25 09:31:07 +0000 |
commit | 857318d3b760aa1ee27b9025746e1f39ce946a53 (patch) | |
tree | 4e9d5900443b375741a9966dee096dee52c01a1c /packet-icmpv6.c | |
parent | 3353ca1d5a8307ce1ae6afd49b3f7525596e0910 (diff) |
Use "tvb_get_string()" instead of allocating a (len+1)-sized buffer,
"tvb_memcpy()"ing to it, and putting in a null terminator;
"tvb_get_string()" will check whether all bytes of the string are
present before allocating the buffer, so that you don't leak memory if
the copy throws an exception, and don't crash if the length is absurdly
large.
Use "tvb_memdup()" instead of allocating a buffer and "tvb_memcpy()"ing
to it, so that an exception is thrown before you try to allocate the
buffer (for the same reasons as listed above).
Before allocating a buffer used when processing a chunk of data from a
packet, get a pointer to the chunk with "tvb_get_ptr()", or check that
the data is all there with "tvb_ensure_bytes_exist()", so that an
exception is thrown before you try to allocate the buffer (for the same
reasons as listed above).
Fix up the lengths of the tvbuff used when dissecting ONC RPC opaque data
with a particular dissector.
svn path=/trunk/; revision=10236
Diffstat (limited to 'packet-icmpv6.c')
-rw-r--r-- | packet-icmpv6.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/packet-icmpv6.c b/packet-icmpv6.c index 6cb240953e..2a50bdb283 100644 --- a/packet-icmpv6.c +++ b/packet-icmpv6.c @@ -1,7 +1,7 @@ /* packet-icmpv6.c * Routines for ICMPv6 packet disassembly * - * $Id: packet-icmpv6.c,v 1.76 2004/01/29 03:59:03 guy Exp $ + * $Id: packet-icmpv6.c,v 1.77 2004/02/25 09:31:06 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -217,16 +217,19 @@ again: case ND_OPT_SOURCE_LINKADDR: case ND_OPT_TARGET_LINKADDR: { - char *t; int len, i, p; + const guint8 *a; + char *t; + + p = offset + sizeof(*opt); len = (opt->nd_opt_len << 3) - sizeof(*opt); + a = tvb_get_ptr(tvb, p, len); t = g_malloc(len * 3); memset(t, 0, len * 3); - p = offset + sizeof(*opt); for (i = 0; i < len; i++) { if (i) t[i * 3 - 1] = ':'; - sprintf(&t[i * 3], "%02x", tvb_get_guint8(tvb, p + i) & 0xff); + sprintf(&t[i * 3], "%02x", a[i]); } proto_tree_add_text(icmp6opt_tree, tvb, offset + sizeof(*opt), len, "Link-layer address: %s", t); |