Ethereal-dev: Re: [Ethereal-dev] [patch]: asn1_string_value_decode

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Matthijs Melchior <mmelchior@xxxxxxxxx>
Date: Fri, 29 Aug 2003 20:52:06 +0200
My patch yesterday with this subject was incorrect!

Here is the correct version, much beter tested and I have really
seen it works....

Matthijs Melchior wrote:

Hi,
   Here is a patch to ensure that 'asn1_string_value_decode' will
return a '\0' terminated string, as opposed to just a byte array of
the requested length. This makes further processing, such as filtering,
much simpler [no more realloc required...].

Please apply this version.

Thanks,

--
Regards,
----------------------------------------------------------------  -o)
Matthijs Melchior                                       Maarssen  /\\
mmelchior@xxxxxxxxx                                  Netherlands _\_v
---------------------------------------------------------------- ----

--- asn1.c-ORG	2003-06-28 18:07:56.000000000 +0200
+++ asn1.c	2003-08-29 20:28:49.000000000 +0200
@@ -661,7 +661,8 @@
  *              Parameters:
  *              asn1:    pointer to ASN1 socket.
  *              enc_len: length of encoding of value.
- *              octets:  pointer to variable we set to point to string.
+ *              octets:  pointer to variable we set to point to string,
+ *			 which is '\0' terminated for ease of use as C-string
  * RETURNS:     ASN1_ERR value (ASN1_ERR_NOERROR on success)
  */
 int
@@ -681,7 +682,7 @@
      */
     if (enc_len != 0) {
 	tvb_ensure_bytes_exist(asn1->tvb, asn1->offset, enc_len);
-	*octets = g_malloc (enc_len);
+	*octets = g_malloc (enc_len+1);
     } else {
 	/*
 	 * If the length is 0, we allocate a 1-byte buffer, as
@@ -702,6 +703,7 @@
 	    return ret;
 	}
     }
+    *(guchar *)ptr = '\0';
     return ASN1_ERR_NOERROR;
 }