aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2009-03-08 22:31:28 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2009-03-08 22:31:28 +0000
commitb4c2f2044ad336e47c789a57da55d2f46ce681ee (patch)
tree09341d52ca598e641a28f5190d59295199f86e04 /epan
parentb663f6d2180e7635b4e8372779452f8aeb3bff48 (diff)
Don't use ep_strndup() to copy the uat protocol name, because the value
can be free'ed before we use it. Allocate the string like we do for other strings and copy/free the memory in the appropriate copy_cb/free_cb functions. This is only used in the DLT_USER table yet. svn path=/trunk/; revision=27663
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-user_encap.c24
-rw-r--r--epan/uat.h2
2 files changed, 22 insertions, 4 deletions
diff --git a/epan/dissectors/packet-user_encap.c b/epan/dissectors/packet-user_encap.c
index 76fd633a82..26d54ebb82 100644
--- a/epan/dissectors/packet-user_encap.c
+++ b/epan/dissectors/packet-user_encap.c
@@ -126,7 +126,25 @@ static void dissect_user(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
}
}
-static void user_update_cb(void* r _U_, const char** err _U_) {
+static void* user_copy_cb(void* dest, const void* orig, unsigned len _U_)
+{
+ const user_encap_t *o = orig;
+ user_encap_t *d = dest;
+
+ d->payload_proto_name = g_strdup(o->payload_proto_name);
+ d->header_proto_name = g_strdup(o->header_proto_name);
+ d->trailer_proto_name = g_strdup(o->trailer_proto_name);
+
+ return d;
+}
+
+static void user_free_cb(void* record)
+{
+ user_encap_t *u = record;
+
+ if (u->payload_proto_name) g_free(u->payload_proto_name);
+ if (u->header_proto_name) g_free(u->header_proto_name);
+ if (u->trailer_proto_name) g_free(u->trailer_proto_name);
}
UAT_VS_DEF(user_encap, encap, user_encap_t, WTAP_ENCAP_USER0, ENCAP0_STR)
@@ -177,9 +195,9 @@ void proto_register_user_encap(void)
&num_encaps,
UAT_CAT_FFMT,
"ChUserDLTsSection",
+ user_copy_cb,
NULL,
- user_update_cb,
- NULL,
+ user_free_cb,
user_flds );
prefs_register_uat_preference(module,
diff --git a/epan/uat.h b/epan/uat.h
index 728e13f453..1ba3bfa5e0 100644
--- a/epan/uat.h
+++ b/epan/uat.h
@@ -452,7 +452,7 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out
#define UAT_PROTO_DEF(basename, field_name, dissector_field, name_field, rec_t) \
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, void* u1 _U_, void* u2 _U_) {\
if (len) { \
- ((rec_t*)rec)->name_field = ep_strndup(buf,len); g_strdown(((rec_t*)rec)->name_field ); g_strchug(((rec_t*)rec)->name_field); \
+ ((rec_t*)rec)->name_field = g_strndup(buf,len); g_strdown(((rec_t*)rec)->name_field ); g_strchug(((rec_t*)rec)->name_field); \
((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \
} else { \
((rec_t*)rec)->dissector_field = find_dissector("data"); \