From Oleg Kostenko:
[obnox/wireshark/wip.git] / epan / asn1.c
index f9ff91f85c78d4df6740ad206e5c155ef95c1f86..26c59c6ae688db4058c128e76b42a2ff48d50134 100644 (file)
@@ -3,8 +3,8 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  *
  * Based on "g_asn1.c" from:
  *
 
 #include <glib.h>
 
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
 #include <epan/tvbuff.h>
 #include <epan/asn1.h>
+#include <epan/emem.h>
 
 /*
  * NAME:        asn1_open                                   [API]
@@ -319,7 +316,7 @@ asn1_header_decode(ASN1_SCK *asn1, guint *cls, guint *con, guint *tag,
                        gboolean *defp, guint *lenp)
 {
     int   ret;
-    guint def, len;
+    guint def, len = 0;
 
     ret = asn1_id_decode (asn1, cls, con, tag);
     if (ret != ASN1_ERR_NOERROR)
@@ -900,8 +897,11 @@ asn1_oid_value_decode ( ASN1_SCK *asn1, int enc_len, subid_t **oid, guint *len)
      * but that's another matter; in any case, that would happen only
      * if we had an immensely large tvbuff....)
      */
-    if (enc_len != 0)
-       tvb_ensure_bytes_exist(asn1->tvb, asn1->offset, enc_len);
+    if (enc_len < 1) {
+       *oid = NULL;
+       return ASN1_ERR_LENGTH_MISMATCH;
+    }
+    tvb_ensure_bytes_exist(asn1->tvb, asn1->offset, enc_len);
 
     eoc = asn1->offset + enc_len;
 
@@ -1039,7 +1039,7 @@ done:
 
 /*
  * NAME:        asn1_err_to_str                             [API]
- * SYNOPSIS:    char *asn1_err_to_str
+ * SYNOPSIS:    const char *asn1_err_to_str
  *                  (
  *                      int     err
  *                  )
@@ -1048,10 +1048,10 @@ done:
  *              err: the error code
  * RETURNS:     string for the error
  */
-char *
+const char *
 asn1_err_to_str(int err)
 {
-    char         *errstr;
+    const char   *errstr;
     char         errstrbuf[14+1+1+11+1+1];     /* "Unknown error (%d)\0" */
 
     switch (err) {
@@ -1077,8 +1077,8 @@ asn1_err_to_str(int err)
        break;
 
     default:
-       snprintf(errstrbuf, sizeof errstrbuf, "Unknown error (%d)", err);
-       errstr = errstrbuf;
+       g_snprintf(errstrbuf, sizeof errstrbuf, "Unknown error (%d)", err);
+       errstr = ep_strdup(errstrbuf);
        break;
     }
     return errstr;