aboutsummaryrefslogtreecommitdiffstats
path: root/asn1.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-03-01 02:48:10 +0000
committerGuy Harris <guy@alum.mit.edu>2002-03-01 02:48:10 +0000
commitd8a08e186c8eec199c6b94466fc0210ca4f15045 (patch)
tree6009602e8f6b5b3bebf67bfea15142b33d711b2d /asn1.c
parent84b6b76cf3910dd07d44907f1cb7bb04b09f94c1 (diff)
Add a routine to "asn1.c" to translate ASN1_ERR_ values to strings. Use
that in the SNMP dissector. Check the return values of ASN.1 routines in the LDAP dissector, and have all the subroutines in that disesctor that can return error indications return ASN1_ERR_ values. Have the routines that can supply a pointer to a newly-created protocol-tree item use the right type for items ("proto_item *", not "proto_tree *", even though they are, at least currently, typedefs for the same type), and use "proto_item" for the type of the item a pointer to which is passed to those routines. Before calling those routines, set the item pointer to null, in case the routine fails. Don't check the return value of "parse_filter_strings()" against -1 - that routine can't return -1. svn path=/trunk/; revision=4833
Diffstat (limited to 'asn1.c')
-rw-r--r--asn1.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/asn1.c b/asn1.c
index 4570c0da22..e7cf347832 100644
--- a/asn1.c
+++ b/asn1.c
@@ -1,7 +1,7 @@
/* asn1.c
* Routines for ASN.1 BER dissection
*
- * $Id: asn1.c,v 1.10 2002/02/21 02:05:53 guy Exp $
+ * $Id: asn1.c,v 1.11 2002/03/01 02:48:10 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -60,6 +60,8 @@
# include "config.h"
#endif
+#include <stdio.h>
+
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
@@ -71,6 +73,11 @@
#include <limits.h>
#include <glib.h>
+
+#ifdef NEED_SNPRINTF_H
+# include "snprintf.h"
+#endif
+
#include <epan/tvbuff.h>
#include "asn1.h"
@@ -970,3 +977,50 @@ done:
*nbytes = asn1->offset - start;
return ret;
}
+
+/*
+ * NAME: asn1_err_to_str [API]
+ * SYNOPSIS: char *asn1_err_to_str
+ * (
+ * int err
+ * )
+ * DESCRIPTION: Returns the string corresponding to an ASN.1 library error.
+ * Parameters:
+ * err: the error code
+ * RETURNS: string for the error
+ */
+char *
+asn1_err_to_str(int err)
+{
+ char *errstr;
+ char errstrbuf[14+1+1+11+1+1]; /* "Unknown error (%d)\0" */
+
+ switch (err) {
+
+ case ASN1_ERR_EOC_MISMATCH:
+ errstr = "EOC mismatch";
+ break;
+
+ case ASN1_ERR_WRONG_TYPE:
+ errstr = "Wrong type for that item";
+ break;
+
+ case ASN1_ERR_LENGTH_NOT_DEFINITE:
+ errstr = "Length was indefinite";
+ break;
+
+ case ASN1_ERR_LENGTH_MISMATCH:
+ errstr = "Length mismatch";
+ break;
+
+ case ASN1_ERR_WRONG_LENGTH_FOR_TYPE:
+ errstr = "Wrong length for that item's type";
+ break;
+
+ default:
+ snprintf(errstrbuf, sizeof errstrbuf, "Unknown error (%d)", err);
+ errstr = errstrbuf;
+ break;
+ }
+ return errstr;
+}