summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-ber.c7
-rw-r--r--epan/dissectors/packet-dop.c4
-rw-r--r--epan/dissectors/packet-per.c3
-rw-r--r--epan/dissectors/packet-rtse.c18
-rw-r--r--epan/ftypes/ftype-bytes.c30
-rw-r--r--epan/oids.c26
-rw-r--r--epan/oids.h9
-rw-r--r--epan/to_str.c43
-rw-r--r--epan/to_str.h3
9 files changed, 69 insertions, 74 deletions
diff --git a/epan/dissectors/packet-ber.c b/epan/dissectors/packet-ber.c
index 95c8bc3483..a42e418083 100644
--- a/epan/dissectors/packet-ber.c
+++ b/epan/dissectors/packet-ber.c
@@ -3080,8 +3080,6 @@ dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int
}
/* 8.19 Encoding of an object identifier value.
- * if value_string is non-NULL it must point to a buffer of at least
- * MAX_OID_STR_LEN bytes.
*/
int dissect_ber_object_identifier(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **value_tvb)
{
@@ -3091,7 +3089,7 @@ int dissect_ber_object_identifier(gboolean implicit_tag, asn1_ctx_t *actx, proto
guint32 len;
int eoffset;
int hoffset;
- char *str;
+ const char *str;
proto_item *cause;
header_field_info *hfi;
const gchar *name;
@@ -4173,9 +4171,6 @@ proto_reg_handoff_ber(void)
dissector_handle_t ber_handle;
- oid_add_from_string("itu-t","0");
- oid_add_from_string("iso","1");
- oid_add_from_string("joint-iso-itu-t","2");
oid_add_from_string("asn1","2.1");
oid_add_from_string("basic-encoding","2.1.1");
diff --git a/epan/dissectors/packet-dop.c b/epan/dissectors/packet-dop.c
index bbe9339a74..bc76091968 100644
--- a/epan/dissectors/packet-dop.c
+++ b/epan/dissectors/packet-dop.c
@@ -2446,9 +2446,9 @@ static void dissect_ACIItem_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto
static int
call_dop_oid_callback(char *base_oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, char *col_info)
{
- char binding_param[MAX_OID_STR_LEN];
+ char* binding_param;
- g_snprintf(binding_param, MAX_OID_STR_LEN, "%s.%s", base_oid, binding_type ? binding_type : "");
+ binding_param = ep_strdup_printf("%s.%s", base_oid, binding_type ? binding_type : "");
if (col_info && (check_col(pinfo->cinfo, COL_INFO)))
col_append_fstr(pinfo->cinfo, COL_INFO, " %s", col_info);
diff --git a/epan/dissectors/packet-per.c b/epan/dissectors/packet-per.c
index 486a9d6d81..378692e0f9 100644
--- a/epan/dissectors/packet-per.c
+++ b/epan/dissectors/packet-per.c
@@ -40,6 +40,7 @@ proper helper routines
#include <string.h>
#include <math.h>
+#include <epan/oids.h>
#include <epan/to_str.h>
#include <epan/prefs.h>
#include <epan/emem.h>
@@ -800,7 +801,7 @@ guint32
dissect_per_object_identifier(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index, tvbuff_t **value_tvb)
{
guint length;
- char *str;
+ const char *str;
tvbuff_t *val_tvb = NULL;
proto_item *item = NULL;
header_field_info *hfi;
diff --git a/epan/dissectors/packet-rtse.c b/epan/dissectors/packet-rtse.c
index 29775c7060..de0f94a12c 100644
--- a/epan/dissectors/packet-rtse.c
+++ b/epan/dissectors/packet-rtse.c
@@ -60,7 +60,7 @@ int proto_rtse = -1;
static struct SESSION_DATA_STRUCTURE* session = NULL;
-static char object_identifier_id[MAX_OID_STR_LEN];
+static char* object_identifier_id;
static gboolean open_request=FALSE;
/* indirect_reference, used to pick up the signalling so we know what
kind of data is transferred in SES_DATA_TRANSFER_PDUs */
@@ -303,7 +303,7 @@ static int dissect_open(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_,
static int
dissect_rtse_T_t61String(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 143 "rtse.cnf"
+#line 145 "rtse.cnf"
tvbuff_t *string = NULL;
offset = dissect_ber_restricted_string(implicit_tag, BER_UNI_TAG_TeletexString,
actx, tree, tvb, offset, hf_index,
@@ -324,7 +324,7 @@ static int dissect_t61String(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset
static int
dissect_rtse_T_octetString(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 159 "rtse.cnf"
+#line 161 "rtse.cnf"
tvbuff_t *string = NULL;
offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
&string);
@@ -369,7 +369,7 @@ static int dissect_callingSSuserReference(proto_tree *tree _U_, tvbuff_t *tvb _U
static int
dissect_rtse_CommonReference(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 151 "rtse.cnf"
+#line 153 "rtse.cnf"
tvbuff_t *string = NULL;
offset = dissect_ber_restricted_string(implicit_tag, BER_UNI_TAG_UTCTime,
actx, tree, tvb, offset, hf_index,
@@ -410,7 +410,7 @@ static const ber_old_sequence_t SessionConnectionIdentifier_sequence[] = {
static int
dissect_rtse_SessionConnectionIdentifier(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 136 "rtse.cnf"
+#line 138 "rtse.cnf"
if(open_request && check_col(actx->pinfo->cinfo, COL_INFO))
col_append_fstr(actx->pinfo->cinfo, COL_INFO, "Recover");
offset = dissect_ber_old_sequence(implicit_tag, actx, tree, tvb, offset,
@@ -463,7 +463,7 @@ static const value_string rtse_T_applicationProtocol_vals[] = {
static int
dissect_rtse_T_applicationProtocol(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 132 "rtse.cnf"
+#line 134 "rtse.cnf"
offset = dissect_ber_integer(TRUE, actx, tree, tvb, offset, hf_index, &app_proto);
@@ -782,7 +782,9 @@ dissect_rtse_T_indirect_reference(gboolean implicit_tag _U_, tvbuff_t *tvb _U_,
/* look up the indirect reference */
if((oid = find_oid_by_pres_ctx_id(actx->pinfo, indir_ref)) != NULL) {
- g_snprintf(object_identifier_id, MAX_OID_STR_LEN, "%s", oid);
+ object_identifier_id = ep_strdup_printf("%s", oid);
+ } else {
+ *object_identifier_id = '\0';
}
@@ -812,7 +814,7 @@ static int dissect_data_value_descriptor(proto_tree *tree _U_, tvbuff_t *tvb _U_
static int
dissect_rtse_T_single_ASN1_type(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 128 "rtse.cnf"
+#line 130 "rtse.cnf"
offset=call_rtse_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, top_tree);
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c
index 268da752d3..373ab7d8ae 100644
--- a/epan/ftypes/ftype-bytes.c
+++ b/epan/ftypes/ftype-bytes.c
@@ -29,6 +29,7 @@
#include <ctype.h>
#include <epan/addr_resolv.h>
#include <epan/strutil.h>
+#include <epan/oids.h>
#ifdef HAVE_LIBPCRE
#include <pcre.h>
@@ -81,17 +82,40 @@ bytes_repr_len(fvalue_t *fv, ftrepr_t rtype _U_)
}
}
+/*
+ * OID_REPR_LEN:
+ *
+ * 5 for the first byte ([0-2].[0-39].)
+ * for each extra byte if the sub-id is:
+ * 1 byte it can be at most "127." (4 bytes we give it 4)
+ * 2 bytes it can be at most "16383." (6 bytes we give it 8)
+ * 3 bytes it can be at most "2097151." (8 bytes we give it 12)
+ * 4 bytes it can be at most "268435456." (10 bytes we give it 16)
+ * 5 bytes it can be at most "34359738368." (12 bytes we give it 20)
+ *
+ * a 5 bytes encoded subid can already overflow the guint32 that holds a sub-id,
+ * making it a completely different issue!
+ */
+#define OID_REPR_LEN(fv) (5 + (4 * ((fv)->value.bytes->len-1)))
+
static int
oid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
{
- /* more exact computation will come later */
- return fv->value.bytes->len * 3 + 16;
+ return OID_REPR_LEN(fv);
}
static void
oid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
{
- oid_to_str_buf(fv->value.bytes->data, fv->value.bytes->len, buf, oid_repr_len(fv, rtype));
+ const char* oid_str = oid_encoded2string(fv->value.bytes->data,fv->value.bytes->len);
+ /*
+ * XXX:
+ * I'm assuming that oid_repr_len is going to be called before to set buf's size.
+ * or else we might have a BO.
+ * I guess that is why this callback is not passed a length.
+ * -- lego
+ */
+ strncpy(buf,oid_str,OID_REPR_LEN(fv));
}
static void
diff --git a/epan/oids.c b/epan/oids.c
index cbd655de53..baf32687ca 100644
--- a/epan/oids.c
+++ b/epan/oids.c
@@ -76,10 +76,19 @@ static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_ty
if (!oid_root.children) {
char* debug_env = getenv("WIRESHARK_DEBUG_MIBS");
+ guint32 subid;
debuglevel = debug_env ? strtoul(debug_env,NULL,10) : 0;
oid_root.children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_root");
+
+ /*
+ * make sure we got strings at least in the three root-children oids
+ * that way oid_resolved() will always have a string to print
+ */
+ subid = 0; oid_add("itu-t",1,&subid);
+ subid = 1; oid_add("iso",1,&subid);
+ subid = 2; oid_add("joint-iso-itu-t",1,&subid);
}
oid_len--;
@@ -133,6 +142,7 @@ static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_ty
}
void oid_add(const char* name, guint oid_len, guint32 *subids) {
+ g_assert(subids && *subids <= 2);
if (oid_len) {
D(3,("\tOid (from subids): %s %s ",name?name:"NULL", oid_subid2string(subids,oid_len)));
add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,oid_len,subids);
@@ -637,6 +647,8 @@ const char* oid_subid2string(guint32* subids, guint len) {
char* s = ep_alloc0(len*11);
char* w = s;
+ DISSECTOR_ASSERT(subids);
+
do {
w += sprintf(w,"%u.",*subids++);
} while(--len);
@@ -689,13 +701,10 @@ guint oid_string2subid(const char* str, guint32** subids_p) {
return 0;
}
- D(7,("\toid_string2subid: n=%d",n));
-
*subids_p = subids = ep_alloc0(sizeof(guint32)*n);
subids_overflow = subids + n;
do switch(*r) {
case '.':
- D(7,("\toid_string2subid: subid: %p %u",subids,*subids));
subids++;
continue;
case '1' : case '2' : case '3' : case '4' : case '5' :
@@ -710,7 +719,6 @@ guint oid_string2subid(const char* str, guint32** subids_p) {
return 0;
} while(*r++);
- D(7,("\toid_string2subid: ret %u",n));
return n;
}
@@ -761,6 +769,8 @@ oid_info_t* oid_get(guint len, guint32* subids, guint* matched, guint* left) {
oid_info_t* curr_oid = &oid_root;
guint i;
+ DISSECTOR_ASSERT(subids && *subids <= 2);
+
for( i=0; i < len; i++) {
oid_info_t* next_oid = emem_tree_lookup32(curr_oid->children,subids[i]);
if (next_oid) {
@@ -799,6 +809,8 @@ guint oid_subid2encoded(guint subids_len, guint32* subids, guint8** bytes_p) {
guint8* bytes;
guint8* b;
+ DISSECTOR_ASSERT(subids && *subids <= 2);
+
if (subids_len < 2) {
*bytes_p = NULL;
return 0;
@@ -925,7 +937,11 @@ char* oid_test_a2b(guint32 num_subids, guint32* subids) {
const gchar *oid_resolved(guint32 num_subids, guint32* subids) {
guint matched;
guint left;
- oid_info_t* oid = oid_get(num_subids, subids, &matched, &left);
+ oid_info_t* oid;
+
+ DISSECTOR_ASSERT(subids && *subids <= 2);
+
+ oid = oid_get(num_subids, subids, &matched, &left);
while (! oid->name ) {
if (!(oid = oid->parent)) {
diff --git a/epan/oids.h b/epan/oids.h
index 7e9c9eafa5..a32f6b83c1 100644
--- a/epan/oids.h
+++ b/epan/oids.h
@@ -135,9 +135,9 @@ extern const gchar *oid_resolved_from_encoded(const guint8 *oid, gint len);
extern const gchar *oid_resolved_from_string(const gchar *oid_str);
/* these yield two formated strings one resolved and one numeric */
- extern void oid_both(guint oid_len, guint32 *subids, char** resolved_p, char** numeric_p);
- extern void oid_both_from_encoded(const guint8 *oid, gint oid_len, char** resolved_p, char** numeric_p);
- extern void oid_both_from_string(const gchar *oid_str, char** resolved_p, char** numeric_p);
+extern void oid_both(guint oid_len, guint32 *subids, char** resolved_p, char** numeric_p);
+extern void oid_both_from_encoded(const guint8 *oid, gint oid_len, char** resolved_p, char** numeric_p);
+extern void oid_both_from_string(const gchar *oid_str, char** resolved_p, char** numeric_p);
/*
* These return the info for the best match.
@@ -163,6 +163,9 @@ extern void oid_add_from_string(const char* name, const gchar *oid_str);
#define oid_resolv_enabled() (1)
#define oid_resolv_cleanup() ((void)0)
+/* from to_str.h */
+#define oid_to_str(encoid, encoid_len) oid_encoded2string(encoid, encoid_len)
+
/* from former dissectors/format_oid.h */
#define format_oid(oid, oid_length) ((void*)oid_resolved(oid_length,oid))
#define new_format_oid(oid, oid_length, non_decoded, decoded) oid_both(oid_length, oid, non_decoded, decoded)
diff --git a/epan/to_str.c b/epan/to_str.c
index 4555b0d64b..0f05fc62a8 100644
--- a/epan/to_str.c
+++ b/epan/to_str.c
@@ -931,49 +931,6 @@ address_to_str_buf(const address *addr, gchar *buf, int buf_len)
}
}
-gchar* oid_to_str(const guint8 *oid, gint oid_len) {
- gchar *buf;
-
- buf=ep_alloc(MAX_OID_STR_LEN);
- return oid_to_str_buf(oid, oid_len, buf, MAX_OID_STR_LEN);
-}
-
-#define OID_STR_LIMIT (1 + 10 + 4 + 1) /* "." + 10 digits + ".>>>" + '\0' */
-gchar* oid_to_str_buf(const guint8 *oid, gint oid_len, gchar *buf, int buf_len) {
- gint i;
- guint8 byte;
- guint32 subid0, subid;
- gboolean is_first;
- gchar *bufp;
-
- bufp = buf; subid = 0; is_first = TRUE;
- for (i=0; i<oid_len; i++){
- byte = oid[i];
- if ((bufp - buf) > (buf_len - OID_STR_LIMIT)) {
- bufp += g_snprintf(bufp, buf_len-(bufp-buf), ".>>>");
- break;
- }
- subid <<= 7;
- subid |= byte & 0x7F;
- if (byte & 0x80) {
- continue;
- }
- if (is_first) {
- subid0 = 0;
- if (subid >= 40) { subid0++; subid-=40; }
- if (subid >= 40) { subid0++; subid-=40; }
- bufp += g_snprintf(bufp, buf_len-(bufp-buf), "%u.%u", subid0, subid);
- is_first = FALSE;
- } else {
- bufp += g_snprintf(bufp, buf_len-(bufp-buf), ".%u", subid);
- }
- subid = 0;
- }
- *bufp = '\0';
-
- return buf;
-}
-
gchar* guid_to_str(const e_guid_t *guid) {
gchar *buf;
diff --git a/epan/to_str.h b/epan/to_str.h
index 22ea4bc5c1..147a944f06 100644
--- a/epan/to_str.h
+++ b/epan/to_str.h
@@ -30,7 +30,6 @@
#include "nstime.h"
#include "epan/packet_info.h"
-#define MAX_OID_STR_LEN 256
#define GUID_STR_LEN 37
#define MAX_IP_STR_LEN 16
#define MAX_ADDR_STR_LEN 256
@@ -78,8 +77,6 @@ extern void display_epoch_time(gchar *, int, time_t, gint32, time_res_t);
extern gchar* rel_time_to_str(nstime_t*);
extern gchar* rel_time_to_secs_str(nstime_t*);
-extern gchar* oid_to_str(const guint8*, gint);
-extern gchar* oid_to_str_buf(const guint8*, gint, gchar*, int);
extern gchar* guid_to_str(const e_guid_t*);
extern gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);