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-dhcpv6.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-dhcpv6.c')
-rw-r--r-- | packet-dhcpv6.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/packet-dhcpv6.c b/packet-dhcpv6.c index dbb943e2b6..75c3654819 100644 --- a/packet-dhcpv6.c +++ b/packet-dhcpv6.c @@ -5,7 +5,7 @@ * SHIRASAKI Yasuhiro <yasuhiro@gnome.gr.jp> * Tony Lindstrom <tony.lindstrom@ericsson.com> * - * $Id: packet-dhcpv6.c,v 1.10 2004/01/29 03:46:36 guy Exp $ + * $Id: packet-dhcpv6.c,v 1.11 2004/02/25 09:31:05 guy Exp $ * * The information used comes from: * RFC3315.txt @@ -450,12 +450,8 @@ dhcpv6_option(tvbuff_t *tvb, proto_tree *bp_tree, int off, int eoff, "Unknown"), status_code); - if (optlen - 2 > 0) - status_message = g_malloc(optlen - 2 + 1); - if (status_message != 0){ - memset(status_message, 0, optlen - 2 + 1); - status_message = tvb_memcpy(tvb, status_message, off + 2, - optlen - 2); + if (optlen - 2 > 0) { + status_message = tvb_get_string(tvb, off + 2, optlen - 2); proto_tree_add_text(subtree, tvb, off + 2, optlen - 2, "Status Message: %s", status_message); |