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-wsp.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-wsp.c')
-rw-r--r-- | packet-wsp.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/packet-wsp.c b/packet-wsp.c index e47db58263..97093fec12 100644 --- a/packet-wsp.c +++ b/packet-wsp.c @@ -2,7 +2,7 @@ * * Routines to dissect WSP component of WAP traffic. * - * $Id: packet-wsp.c,v 1.108 2004/02/04 20:19:25 obiot Exp $ + * $Id: packet-wsp.c,v 1.109 2004/02/25 09:31:07 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -5645,10 +5645,7 @@ add_post_variable (proto_tree *tree, tvbuff_t *tvb, guint variableStart, guint v char *variableBuffer; char *valueBuffer; - variableBuffer = g_malloc (variableLength+1); - strncpy (variableBuffer, (const char *)tvb_get_ptr (tvb, - variableStart, variableLength), variableLength); - variableBuffer[variableLength] = 0; + variableBuffer = tvb_get_string(tvb, variableStart, variableLength); if (valueEnd < valueStart) { @@ -5659,10 +5656,9 @@ add_post_variable (proto_tree *tree, tvbuff_t *tvb, guint variableStart, guint v else { valueLength = valueEnd-valueStart; - valueBuffer = g_malloc (valueLength+1); - strncpy (valueBuffer, (const char *)tvb_get_ptr (tvb, - valueStart, valueLength), valueLength); - valueBuffer[valueLength] = 0; + /* XXX - if this throws an exception, "variableBuffer" + is leaked */ + valueBuffer = tvb_get_string(tvb, valueStart, valueLength); } /* Check for variables with no value */ |