diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-05-13 01:24:47 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-05-13 01:24:47 +0000 |
commit | b6e941027ff5b41a55bf23ce43d23e8ea5d49efc (patch) | |
tree | 3becaf90450ff578c7dc8dbcd051987b3ee15ba4 /asn1.c | |
parent | ef67bf2d2f260b3e58cfb19ba550b517fb1196c0 (diff) |
Add a "tvb_ensure_bytes_exist()", which is like "tvb_bytes_exist()" only
it throws the appropriate exception if the bytes don't exist. Use it in
the GIOP and ASN.1 code to check whether the bytes to be copied to a
buffer exist before allocating the buffer.
Make "check_offset_length_no_exception()" check for an overflow, so that
it can be used in "tvb_ensure_bytes_exist()" and do all the checking
that the code "tvb_ensure_bytes_exist()" replaces did.
Make "get_CDR_wchar()" return a "gint", so that if the length octet it
fetched has a value between 128 and 255, the length can be returned
correctly.
Fix some comments not to specify the exception thrown by various
routines that can throw various exceptions.
svn path=/trunk/; revision=5453
Diffstat (limited to 'asn1.c')
-rw-r--r-- | asn1.c | 34 |
1 files changed, 7 insertions, 27 deletions
@@ -1,7 +1,7 @@ /* asn1.c * Routines for ASN.1 BER dissection * - * $Id: asn1.c,v 1.12 2002/03/05 09:18:58 guy Exp $ + * $Id: asn1.c,v 1.13 2002/05/13 01:24:45 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -655,27 +655,15 @@ asn1_string_value_decode ( ASN1_SCK *asn1, int enc_len, guchar **octets) int eoc; guchar *ptr; - eoc = asn1->offset + enc_len; - - /* - * Check for an overflow, and clamp "eoc" at the maximum if we - * get it. - */ - if (eoc < asn1->offset || eoc < 0) - eoc = INT_MAX; - /* * First, make sure the entire string is in the tvbuff, and throw * an exception if it isn't. If the length is bogus, this should * keep us from trying to allocate an immensely large buffer. * (It won't help if the length is *valid* but immensely large, * but that's another matter.) - * - * We do that by attempting to fetch the last byte (if the length - * isn't 0). */ if (enc_len != 0) { - tvb_get_guint8(asn1->tvb, eoc - 1); + tvb_ensure_bytes_exist(asn1->tvb, asn1->offset, enc_len); *octets = g_malloc (enc_len); } else { /* @@ -686,6 +674,8 @@ asn1_string_value_decode ( ASN1_SCK *asn1, int enc_len, guchar **octets) */ *octets = g_malloc (1); } + + eoc = asn1->offset + enc_len; ptr = *octets; while (asn1->offset < eoc) { ret = asn1_octet_decode (asn1, (guchar *)ptr++); @@ -832,27 +822,17 @@ asn1_oid_value_decode ( ASN1_SCK *asn1, int enc_len, subid_t **oid, guint *len) guint size; subid_t *optr; - eoc = asn1->offset + enc_len; - - /* - * Check for an overflow, and clamp "eoc" at the maximum if we - * get it. - */ - if (eoc < asn1->offset || eoc < 0) - eoc = INT_MAX; - /* * First, make sure the entire string is in the tvbuff, and throw * an exception if it isn't. If the length is bogus, this should * keep us from trying to allocate an immensely large buffer. * (It won't help if the length is *valid* but immensely large, * but that's another matter.) - * - * We do that by attempting to fetch the last byte (if the length - * isn't 0). */ if (enc_len != 0) - tvb_get_guint8(asn1->tvb, eoc - 1); + tvb_ensure_bytes_exist(asn1->tvb, asn1->offset, enc_len); + + eoc = asn1->offset + enc_len; size = enc_len + 1; *oid = g_malloc(size * sizeof(gulong)); |