summaryrefslogtreecommitdiff
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-07-15 01:31:16 -0700
committerGuy Harris <guy@alum.mit.edu>2016-07-15 08:31:55 +0000
commit996dcc038dea197924285a6717b522a57f95fd65 (patch)
tree064ca576e610eb4ce34f290235dcd1d719368a8b /wiretap
parentced207150542f59f395fc4052d8a7cdfba67effa (diff)
downloadwireshark-996dcc038dea197924285a6717b522a57f95fd65.tar.gz
Do a deep copy in wtap_block_add_custom_option().
That way, we don't have to worry about multiple instances of an option pointing to the same data. and having to worry about freeing data that's pointed to by another instance. Change-Id: I3470a9eebf346023713fd0d6ff2451d727c25089 Reviewed-on: https://code.wireshark.org/review/16471 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/erf.c4
-rw-r--r--wiretap/pcapng.c4
-rw-r--r--wiretap/wtap.h2
-rw-r--r--wiretap/wtap_opttypes.c40
4 files changed, 45 insertions, 5 deletions
diff --git a/wiretap/erf.c b/wiretap/erf.c
index e694ade9b2..8d63fb2f51 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -1561,6 +1561,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
case ERF_META_TAG_filter:
if_filter.if_filter_str = g_strndup((gchar*) tag.value, tag.length);
wtap_block_add_custom_option(int_data, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
+ g_free(if_filter.if_filter_str);
if_info->set_flags.filter = 1;
break;
default:
@@ -1583,7 +1584,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
*/
if (state->if_map->module_filter_str && !if_info->set_flags.filter) {
/* Duplicate because might use with multiple interfaces */
- if_filter.if_filter_str = g_strdup(state->if_map->module_filter_str);
+ if_filter.if_filter_str = state->if_map->module_filter_str;
wtap_block_add_custom_option(int_data, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
/*
* Don't set flag because stream is more specific than module. Interface
@@ -1727,6 +1728,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud
if (!if_info->set_flags.filter) {
if_filter.if_filter_str = g_strndup((gchar*) tag.value, tag.length);
wtap_block_add_custom_option(int_data, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
+ g_free(if_filter.if_filter_str);
if_info->set_flags.filter = 1;
}
break;
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index a46d976197..62c730ca3e 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -885,11 +885,11 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh,
pcapng_debug("pcapng_read_if_descr_block: if_filter_str %s oh.option_length %u", if_filter.if_filter_str, oh.option_length);
} else if (option_content[0] == 1) {
if_filter.bpf_filter_len = oh.option_length-1;
- if_filter.if_filter_bpf_bytes = (gchar *)g_malloc(oh.option_length-1);
- memcpy(if_filter.if_filter_bpf_bytes, (char *)option_content+1, oh.option_length-1);
+ if_filter.if_filter_bpf_bytes = (guint8 *)option_content+1;
}
/* Fails with multiple options; we silently ignore the failure */
wtap_block_add_custom_option(wblock->block, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
+ g_free(if_filter.if_filter_str);
} else {
pcapng_debug("pcapng_read_if_descr_block: if_filter length %u seems strange", oh.option_length);
}
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 566ec50a75..20a3b188f3 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1297,7 +1297,7 @@ typedef struct wtapng_if_descr_filter_s {
* libpcap string.
*/
guint16 bpf_filter_len; /** variant II BPF filter len 0 if not used*/
- gchar *if_filter_bpf_bytes; /** BPF filter or NULL */
+ guint8 *if_filter_bpf_bytes; /** BPF filter or NULL */
} wtapng_if_descr_filter_t;
/**
diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c
index 27b0fe28ed..c1e59ff1b3 100644
--- a/wiretap/wtap_opttypes.c
+++ b/wiretap/wtap_opttypes.c
@@ -48,6 +48,7 @@ typedef struct {
GArray *options; /**< array of known options */
} wtap_blocktype_t;
+typedef void *(*wtap_opttype_dup_custom_func)(void* src);
typedef void (*wtap_opttype_free_custom_func)(void* data);
/*
@@ -58,6 +59,7 @@ typedef struct {
const char *description; /**< human-readable description of option */
wtap_opttype_e data_type; /**< data type of that option */
guint flags; /**< flags for the option */
+ wtap_opttype_dup_custom_func dup_func; /**< function to duplicate custom option data */
wtap_opttype_free_custom_func free_func; /**< function to free custom option data */
} wtap_opttype_t;
@@ -86,6 +88,7 @@ static void wtap_opttype_block_register(wtap_block_type_t block_type, wtap_block
"Comment",
WTAP_OPTTYPE_STRING,
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED,
+ NULL,
NULL
};
@@ -788,12 +791,14 @@ wtap_block_add_custom_option(wtap_block_t block, guint option_id, void *value, s
{
wtap_opttype_return_val ret;
wtap_option_t *opt;
+ wtap_opttype_t *opttype;
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_CUSTOM, &opt);
if (ret != WTAP_OPTTYPE_SUCCESS)
return ret;
+ opttype = &g_array_index(block->info->options, wtap_opttype_t, opt->option_id);
opt->value.customval.size = (guint)value_size;
- opt->value.customval.data = g_memdup(value, (guint)value_size);
+ opt->value.customval.data = opttype->dup_func(value);
return WTAP_OPTTYPE_SUCCESS;
}
@@ -861,6 +866,19 @@ static void isb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
memcpy(dest_block->mandatory_data, src_block->mandatory_data, sizeof(wtapng_if_stats_mandatory_t));
}
+static void *idb_filter_dup(void* src)
+{
+ wtapng_if_descr_filter_t* filter_src = (wtapng_if_descr_filter_t*)src;
+ wtapng_if_descr_filter_t* filter_dest;
+
+ /* Deep copy. */
+ filter_dest = g_malloc(sizeof (wtapng_if_descr_filter_t));
+ filter_dest->if_filter_str = g_strdup(filter_src->if_filter_str);
+ filter_dest->bpf_filter_len = filter_src->bpf_filter_len;
+ filter_dest->if_filter_bpf_bytes = g_memdup(filter_src->if_filter_bpf_bytes, filter_src->bpf_filter_len);
+ return (void *)filter_dest;
+}
+
static void idb_filter_free(void* data)
{
wtapng_if_descr_filter_t* filter = (wtapng_if_descr_filter_t*)data;
@@ -929,6 +947,7 @@ void wtap_opttypes_initialize(void)
"SHB Hardware",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
static wtap_opttype_t shb_os = {
@@ -936,6 +955,7 @@ void wtap_opttypes_initialize(void)
"SHB Operating System",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
static wtap_opttype_t shb_userappl = {
@@ -943,6 +963,7 @@ void wtap_opttypes_initialize(void)
"SHB User Application",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
@@ -960,6 +981,7 @@ void wtap_opttypes_initialize(void)
"IDB Name",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
static wtap_opttype_t if_description = {
@@ -967,6 +989,7 @@ void wtap_opttypes_initialize(void)
"IDB Description",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
static wtap_opttype_t if_speed = {
@@ -974,6 +997,7 @@ void wtap_opttypes_initialize(void)
"IDB Speed",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t if_tsresol = {
@@ -981,6 +1005,7 @@ void wtap_opttypes_initialize(void)
"IDB Time Stamp Resolution",
WTAP_OPTTYPE_UINT8, /* XXX - signed? */
0,
+ NULL,
NULL
};
static wtap_opttype_t if_filter = {
@@ -988,6 +1013,7 @@ void wtap_opttypes_initialize(void)
"IDB Filter",
WTAP_OPTTYPE_CUSTOM,
0,
+ idb_filter_dup,
idb_filter_free
};
static wtap_opttype_t if_os = {
@@ -995,6 +1021,7 @@ void wtap_opttypes_initialize(void)
"IDB Operating System",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
static wtap_opttype_t if_fcslen = {
@@ -1002,6 +1029,7 @@ void wtap_opttypes_initialize(void)
"IDB FCS Length",
WTAP_OPTTYPE_UINT8,
0,
+ NULL,
NULL
};
@@ -1019,6 +1047,7 @@ void wtap_opttypes_initialize(void)
"NRB DNS server name",
WTAP_OPTTYPE_STRING,
0,
+ NULL,
NULL
};
static wtap_opttype_t ns_dnsIP4addr = {
@@ -1026,6 +1055,7 @@ void wtap_opttypes_initialize(void)
"NRB DNS server IPv4 address",
WTAP_OPTTYPE_IPv4,
0,
+ NULL,
NULL
};
static wtap_opttype_t ns_dnsIP6addr = {
@@ -1033,6 +1063,7 @@ void wtap_opttypes_initialize(void)
"NRB DNS server IPv6 address",
WTAP_OPTTYPE_IPv6,
0,
+ NULL,
NULL
};
@@ -1050,6 +1081,7 @@ void wtap_opttypes_initialize(void)
"ISB Start Time",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t isb_endtime = {
@@ -1057,6 +1089,7 @@ void wtap_opttypes_initialize(void)
"ISB End Time",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t isb_ifrecv = {
@@ -1064,6 +1097,7 @@ void wtap_opttypes_initialize(void)
"ISB Received Packets",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t isb_ifdrop = {
@@ -1071,6 +1105,7 @@ void wtap_opttypes_initialize(void)
"ISB Dropped Packets",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t isb_filteraccept = {
@@ -1078,6 +1113,7 @@ void wtap_opttypes_initialize(void)
"ISB Packets Accepted By Filter",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t isb_osdrop = {
@@ -1085,6 +1121,7 @@ void wtap_opttypes_initialize(void)
"ISB Packets Dropped By The OS",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};
static wtap_opttype_t isb_usrdeliv = {
@@ -1092,6 +1129,7 @@ void wtap_opttypes_initialize(void)
"ISB Packets Delivered To The User",
WTAP_OPTTYPE_UINT64,
0,
+ NULL,
NULL
};