diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols index 4c3135dbf4..e356c54c9e 100644 --- a/debian/libwsutil0.symbols +++ b/debian/libwsutil0.symbols @@ -71,6 +71,7 @@ libwsutil.so.0 libwsutil0 #MINVER# find_last_pathname_separator@Base 1.12.0~rc1 format_size@Base 1.10.0 free_progdirs@Base 2.3.0 + g_memdup2@Base 3.5.0 get_basename@Base 1.12.0~rc1 get_copyright_info@Base 1.99.0 get_cur_groupname@Base 1.10.0 diff --git a/dumpcap.c b/dumpcap.c index 609efa488a..e7e976b77d 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -86,6 +86,7 @@ #include "wsutil/inet_addr.h" #include "wsutil/time_util.h" #include "wsutil/please_report_bug.h" +#include "wsutil/glib-compat.h" #include "caputils/ws80211_utils.h" @@ -2116,7 +2117,7 @@ pcapng_adjust_block(capture_src *pcap_src, const pcapng_block_header_t *bh, u_ch * buffer files. */ g_free(global_ld.saved_shb); - global_ld.saved_shb = (guint8 *) g_memdup(pd, bh->block_total_length); + global_ld.saved_shb = (guint8 *) g_memdup2(pd, bh->block_total_length); /* * We're dealing with one section at a time, so we can (and must) @@ -2155,7 +2156,7 @@ pcapng_adjust_block(capture_src *pcap_src, const pcapng_block_header_t *bh, u_ch saved_idb_t idb_source = { 0 }; idb_source.interface_id = pcap_src->interface_id; idb_source.idb_len = bh->block_total_length; - idb_source.idb = (guint8 *) g_memdup(pd, idb_source.idb_len); + idb_source.idb = (guint8 *) g_memdup2(pd, idb_source.idb_len); g_array_append_val(global_ld.saved_idbs, idb_source); guint32 iface_id = global_ld.saved_idbs->len - 1; g_array_append_val(pcap_src->cap_pipe_info.pcapng.src_iface_to_global, iface_id); diff --git a/epan/crypt/dot11decrypt.c b/epan/crypt/dot11decrypt.c index c055127ce4..a9c1e40971 100644 --- a/epan/crypt/dot11decrypt.c +++ b/epan/crypt/dot11decrypt.c @@ -16,6 +16,7 @@ #include #include #include +#include #include /* for DISSECTOR_ASSERT. */ #include @@ -367,7 +368,7 @@ Dot11DecryptRc4KeyData(const guint8 *decryption_key, guint decryption_key_len, gcry_cipher_close(rc4_handle); return NULL; } - decrypted_key = (guint8 *)g_memdup(encrypted_keydata, encrypted_keydata_len); + decrypted_key = (guint8 *)g_memdup2(encrypted_keydata, encrypted_keydata_len); if (!decrypted_key) { gcry_cipher_close(rc4_handle); return NULL; @@ -573,7 +574,7 @@ Dot11DecryptAddSa( if (existing_sa != NULL) { sa = Dot11DecryptPrependSa(existing_sa, sa); } else { - void *key = g_memdup(id, sizeof(DOT11DECRYPT_SEC_ASSOCIATION_ID)); + void *key = g_memdup2(id, sizeof(DOT11DECRYPT_SEC_ASSOCIATION_ID)); g_hash_table_insert(ctx->sa_hash, key, sa); } return sa; diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c index fbc819f092..2b654b85bf 100644 --- a/epan/dfilter/dfilter-macro.c +++ b/epan/dfilter/dfilter-macro.c @@ -22,6 +22,7 @@ #include #include #include +#include typedef struct { const char* name; @@ -485,7 +486,7 @@ static void* macro_copy(void* dest, const void* orig, size_t len _U_) { */ do nparts++; while (m->parts[nparts]); - d->parts = (gchar **)g_memdup(m->parts,(nparts+1)*(guint)sizeof(void*)); + d->parts = (gchar **)g_memdup2(m->parts,(nparts+1)*(guint)sizeof(void*)); nparts = 0; while(m->parts[nparts]) { if(nparts) { @@ -500,7 +501,7 @@ static void* macro_copy(void* dest, const void* orig, size_t len _U_) { * Clone the contents of m->args_pos into d->args_pos. */ - d->args_pos = (int *)g_memdup(m->args_pos,(--nparts)*(guint)sizeof(int)); + d->args_pos = (int *)g_memdup2(m->args_pos,(--nparts)*(guint)sizeof(int)); } DUMP_MACRO(d); diff --git a/epan/dissectors/asn1/c1222/packet-c1222-template.c b/epan/dissectors/asn1/c1222/packet-c1222-template.c index 7b3a1ca5b3..13de7f21d1 100644 --- a/epan/dissectors/asn1/c1222/packet-c1222-template.c +++ b/epan/dissectors/asn1/c1222/packet-c1222-template.c @@ -717,7 +717,7 @@ c1222_uat_data_copy_cb(void *dest, const void *source, size_t len _U_) d->keynum = o->keynum; d->keylen = o->keylen; - d->key = (guchar *)g_memdup(o->key, o->keylen); + d->key = (guchar *)g_memdup2(o->key, o->keylen); return dest; } diff --git a/epan/dissectors/asn1/kerberos/packet-kerberos-template.c b/epan/dissectors/asn1/kerberos/packet-kerberos-template.c index 6caa2e6dbc..68b64b4f09 100644 --- a/epan/dissectors/asn1/kerberos/packet-kerberos-template.c +++ b/epan/dissectors/asn1/kerberos/packet-kerberos-template.c @@ -2169,7 +2169,7 @@ add_encryption_key(packet_info *pinfo, int keytype, int keylength, const char *k new_key->kvno = 0; new_key->keytype = keytype; new_key->length = keylength; - new_key->contents = g_memdup(keyvalue, keylength); + new_key->contents = g_memdup2(keyvalue, keylength); g_snprintf(new_key->origin, KRB_MAX_ORIG_LEN, "%s learnt from frame %u", origin, pinfo->num); service_key_list = g_slist_append(service_key_list, (gpointer) new_key); } @@ -2297,7 +2297,7 @@ read_keytab_file(const char *service_key_file) sk->kvno = buf[0] << 8 | buf[1]; sk->keytype = KEYTYPE_DES3_CBC_MD5; sk->length = DES3_KEY_SIZE; - sk->contents = g_memdup(buf + 2, DES3_KEY_SIZE); + sk->contents = g_memdup2(buf + 2, DES3_KEY_SIZE); g_snprintf(sk->origin, KRB_MAX_ORIG_LEN, "3DES service key file, key #%d, offset %ld", count, ftell(skf)); service_key_list = g_slist_append(service_key_list, (gpointer) sk); if (fseek(skf, newline_skip, SEEK_CUR) < 0) { diff --git a/epan/dissectors/asn1/snmp/packet-snmp-template.c b/epan/dissectors/asn1/snmp/packet-snmp-template.c index 689ee2aadf..503e02e3f9 100644 --- a/epan/dissectors/asn1/snmp/packet-snmp-template.c +++ b/epan/dissectors/asn1/snmp/packet-snmp-template.c @@ -1427,25 +1427,25 @@ static void set_ue_keys(snmp_ue_assoc_t* n ) { static snmp_ue_assoc_t* ue_dup(snmp_ue_assoc_t* o) { - snmp_ue_assoc_t* d = (snmp_ue_assoc_t*)g_memdup(o,sizeof(snmp_ue_assoc_t)); + snmp_ue_assoc_t* d = (snmp_ue_assoc_t*)g_memdup2(o,sizeof(snmp_ue_assoc_t)); d->user.authModel = o->user.authModel; d->user.privProtocol = o->user.privProtocol; - d->user.userName.data = (guint8 *)g_memdup(o->user.userName.data,o->user.userName.len); + d->user.userName.data = (guint8 *)g_memdup2(o->user.userName.data,o->user.userName.len); d->user.userName.len = o->user.userName.len; - d->user.authPassword.data = o->user.authPassword.data ? (guint8 *)g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL; + d->user.authPassword.data = o->user.authPassword.data ? (guint8 *)g_memdup2(o->user.authPassword.data,o->user.authPassword.len) : NULL; d->user.authPassword.len = o->user.authPassword.len; - d->user.privPassword.data = o->user.privPassword.data ? (guint8 *)g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL; + d->user.privPassword.data = o->user.privPassword.data ? (guint8 *)g_memdup2(o->user.privPassword.data,o->user.privPassword.len) : NULL; d->user.privPassword.len = o->user.privPassword.len; d->engine.len = o->engine.len; if (d->engine.len) { - d->engine.data = (guint8 *)g_memdup(o->engine.data,o->engine.len); + d->engine.data = (guint8 *)g_memdup2(o->engine.data,o->engine.len); set_ue_keys(d); } @@ -1465,24 +1465,24 @@ snmp_users_copy_cb(void* dest, const void* orig, size_t len _U_) d->priv_proto = o->priv_proto; d->user.privProtocol = priv_protos[o->priv_proto]; - d->user.userName.data = (guint8*)g_memdup(o->user.userName.data,o->user.userName.len); + d->user.userName.data = (guint8*)g_memdup2(o->user.userName.data,o->user.userName.len); d->user.userName.len = o->user.userName.len; - d->user.authPassword.data = o->user.authPassword.data ? (guint8*)g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL; + d->user.authPassword.data = o->user.authPassword.data ? (guint8*)g_memdup2(o->user.authPassword.data,o->user.authPassword.len) : NULL; d->user.authPassword.len = o->user.authPassword.len; - d->user.privPassword.data = o->user.privPassword.data ? (guint8*)g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL; + d->user.privPassword.data = o->user.privPassword.data ? (guint8*)g_memdup2(o->user.privPassword.data,o->user.privPassword.len) : NULL; d->user.privPassword.len = o->user.privPassword.len; d->engine.len = o->engine.len; if (o->engine.data) { - d->engine.data = (guint8*)g_memdup(o->engine.data,o->engine.len); + d->engine.data = (guint8*)g_memdup2(o->engine.data,o->engine.len); } - d->user.authKey.data = o->user.authKey.data ? (guint8*)g_memdup(o->user.authKey.data,o->user.authKey.len) : NULL; + d->user.authKey.data = o->user.authKey.data ? (guint8*)g_memdup2(o->user.authKey.data,o->user.authKey.len) : NULL; d->user.authKey.len = o->user.authKey.len; - d->user.privKey.data = o->user.privKey.data ? (guint8*)g_memdup(o->user.privKey.data,o->user.privKey.len) : NULL; + d->user.privKey.data = o->user.privKey.data ? (guint8*)g_memdup2(o->user.privKey.data,o->user.privKey.len) : NULL; d->user.privKey.len = o->user.privKey.len; return d; @@ -1601,17 +1601,17 @@ renew_ue_cache(void) static snmp_ue_assoc_t* localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len ) { - snmp_ue_assoc_t* n = (snmp_ue_assoc_t*)g_memdup(o,sizeof(snmp_ue_assoc_t)); + snmp_ue_assoc_t* n = (snmp_ue_assoc_t*)g_memdup2(o,sizeof(snmp_ue_assoc_t)); - n->user.userName.data = (guint8*)g_memdup(o->user.userName.data,o->user.userName.len); + n->user.userName.data = (guint8*)g_memdup2(o->user.userName.data,o->user.userName.len); n->user.authModel = o->user.authModel; - n->user.authPassword.data = (guint8*)g_memdup(o->user.authPassword.data,o->user.authPassword.len); + n->user.authPassword.data = (guint8*)g_memdup2(o->user.authPassword.data,o->user.authPassword.len); n->user.authPassword.len = o->user.authPassword.len; - n->user.privPassword.data = (guint8*)g_memdup(o->user.privPassword.data,o->user.privPassword.len); + n->user.privPassword.data = (guint8*)g_memdup2(o->user.privPassword.data,o->user.privPassword.len); n->user.privPassword.len = o->user.privPassword.len; - n->user.authKey.data = (guint8*)g_memdup(o->user.authKey.data,o->user.authKey.len); - n->user.privKey.data = (guint8*)g_memdup(o->user.privKey.data,o->user.privKey.len); - n->engine.data = (guint8*)g_memdup(engine,engine_len); + n->user.authKey.data = (guint8*)g_memdup2(o->user.authKey.data,o->user.authKey.len); + n->user.privKey.data = (guint8*)g_memdup2(o->user.privKey.data,o->user.privKey.len); + n->engine.data = (guint8*)g_memdup2(engine,engine_len); n->engine.len = engine_len; n->priv_proto = o->priv_proto; diff --git a/epan/dissectors/packet-c1222.c b/epan/dissectors/packet-c1222.c index e15fd650eb..2f0797cda7 100644 --- a/epan/dissectors/packet-c1222.c +++ b/epan/dissectors/packet-c1222.c @@ -768,7 +768,7 @@ c1222_uat_data_copy_cb(void *dest, const void *source, size_t len _U_) d->keynum = o->keynum; d->keylen = o->keylen; - d->key = (guchar *)g_memdup(o->key, o->keylen); + d->key = (guchar *)g_memdup2(o->key, o->keylen); return dest; } diff --git a/epan/dissectors/packet-http.c b/epan/dissectors/packet-http.c index c44d89782c..d052b159fc 100644 --- a/epan/dissectors/packet-http.c +++ b/epan/dissectors/packet-http.c @@ -359,7 +359,7 @@ http_eo_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const entry->content_type = g_strdup(eo_info->content_type); entry->filename = eo_info->filename ? g_path_get_basename(eo_info->filename) : NULL; entry->payload_len = eo_info->payload_len; - entry->payload_data = (guint8 *)g_memdup(eo_info->payload_data, eo_info->payload_len); + entry->payload_data = (guint8 *)g_memdup2(eo_info->payload_data, eo_info->payload_len); object_list->add_entry(object_list->gui_data, entry); diff --git a/epan/dissectors/packet-ieee802154.c b/epan/dissectors/packet-ieee802154.c index 04f2f3cbbc..37d4c365d1 100644 --- a/epan/dissectors/packet-ieee802154.c +++ b/epan/dissectors/packet-ieee802154.c @@ -210,7 +210,7 @@ addr_uat_copy_cb(void *dest, const void *source, size_t len _U_) const static_addr_t* o = (const static_addr_t*)source; static_addr_t* d = (static_addr_t*)dest; - d->eui64 = (guchar *)g_memdup(o->eui64, o->eui64_len); + d->eui64 = (guchar *)g_memdup2(o->eui64, o->eui64_len); d->eui64_len = o->eui64_len; d->addr16 = o->addr16; d->pan = o->pan; diff --git a/epan/dissectors/packet-imf.c b/epan/dissectors/packet-imf.c index 1ad5c83d70..f4f929afc5 100644 --- a/epan/dissectors/packet-imf.c +++ b/epan/dissectors/packet-imf.c @@ -178,7 +178,7 @@ imf_eo_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const entry->content_type = g_strdup("EML file"); entry->filename = g_strdup_printf("%s.eml", eo_info->subject_data); entry->payload_len = eo_info->payload_len; - entry->payload_data = (guint8 *)g_memdup(eo_info->payload_data, eo_info->payload_len); + entry->payload_data = (guint8 *)g_memdup2(eo_info->payload_data, eo_info->payload_len); object_list->add_entry(object_list->gui_data, entry); diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c index 57b2733fe8..efbd891089 100644 --- a/epan/dissectors/packet-isakmp.c +++ b/epan/dissectors/packet-isakmp.c @@ -6315,9 +6315,9 @@ ikev1_uat_data_copy_cb(void *dest, const void *source, size_t len _U_) const ikev1_uat_data_key_t* o = (const ikev1_uat_data_key_t*)source; ikev1_uat_data_key_t* d = (ikev1_uat_data_key_t*)dest; - d->icookie = (guchar *)g_memdup(o->icookie, o->icookie_len); + d->icookie = (guchar *)g_memdup2(o->icookie, o->icookie_len); d->icookie_len = o->icookie_len; - d->key = (guchar *)g_memdup(o->key, o->key_len); + d->key = (guchar *)g_memdup2(o->key, o->key_len); d->key_len = o->key_len; return dest; @@ -6346,29 +6346,29 @@ ikev2_uat_data_copy_cb(void *dest, const void *source, size_t len _U_) const ikev2_uat_data_t* o = (const ikev2_uat_data_t*)source; ikev2_uat_data_t* d = (ikev2_uat_data_t*)dest; - d->key.spii = (guchar *)g_memdup(o->key.spii, o->key.spii_len); + d->key.spii = (guchar *)g_memdup2(o->key.spii, o->key.spii_len); d->key.spii_len = o->key.spii_len; - d->key.spir = (guchar *)g_memdup(o->key.spir, o->key.spir_len); + d->key.spir = (guchar *)g_memdup2(o->key.spir, o->key.spir_len); d->key.spir_len = o->key.spir_len; d->encr_alg = o->encr_alg; d->auth_alg = o->auth_alg; - d->sk_ei = (guchar *)g_memdup(o->sk_ei, o->sk_ei_len); + d->sk_ei = (guchar *)g_memdup2(o->sk_ei, o->sk_ei_len); d->sk_ei_len = o->sk_ei_len; - d->sk_er = (guchar *)g_memdup(o->sk_er, o->sk_er_len); + d->sk_er = (guchar *)g_memdup2(o->sk_er, o->sk_er_len); d->sk_er_len = o->sk_er_len; - d->sk_ai = (guchar *)g_memdup(o->sk_ai, o->sk_ai_len); + d->sk_ai = (guchar *)g_memdup2(o->sk_ai, o->sk_ai_len); d->sk_ai_len = o->sk_ai_len; - d->sk_ar = (guchar *)g_memdup(o->sk_ar, o->sk_ar_len); + d->sk_ar = (guchar *)g_memdup2(o->sk_ar, o->sk_ar_len); d->sk_ar_len = o->sk_ar_len; - d->encr_spec = (ikev2_encr_alg_spec_t *)g_memdup(o->encr_spec, sizeof(ikev2_encr_alg_spec_t)); - d->auth_spec = (ikev2_auth_alg_spec_t *)g_memdup(o->auth_spec, sizeof(ikev2_auth_alg_spec_t)); + d->encr_spec = (ikev2_encr_alg_spec_t *)g_memdup2(o->encr_spec, sizeof(ikev2_encr_alg_spec_t)); + d->auth_spec = (ikev2_auth_alg_spec_t *)g_memdup2(o->auth_spec, sizeof(ikev2_auth_alg_spec_t)); return dest; } diff --git a/epan/dissectors/packet-k12.c b/epan/dissectors/packet-k12.c index dd08af5423..ef2d65717a 100644 --- a/epan/dissectors/packet-k12.c +++ b/epan/dissectors/packet-k12.c @@ -332,7 +332,7 @@ k12_copy_cb(void* dest, const void* orig, size_t len _U_) d->match = g_strdup(o->match); d->protos = g_strdup(o->protos); - d->handles = (dissector_handle_t *)g_memdup(o->handles,(guint)(sizeof(dissector_handle_t)*(num_protos+1))); + d->handles = (dissector_handle_t *)g_memdup2(o->handles,(guint)(sizeof(dissector_handle_t)*(num_protos+1))); g_strfreev(protos); diff --git a/epan/dissectors/packet-kerberos.c b/epan/dissectors/packet-kerberos.c index b586bbf79e..87d7aed1d4 100644 --- a/epan/dissectors/packet-kerberos.c +++ b/epan/dissectors/packet-kerberos.c @@ -2609,7 +2609,7 @@ add_encryption_key(packet_info *pinfo, int keytype, int keylength, const char *k new_key->kvno = 0; new_key->keytype = keytype; new_key->length = keylength; - new_key->contents = g_memdup(keyvalue, keylength); + new_key->contents = g_memdup2(keyvalue, keylength); g_snprintf(new_key->origin, KRB_MAX_ORIG_LEN, "%s learnt from frame %u", origin, pinfo->num); service_key_list = g_slist_append(service_key_list, (gpointer) new_key); } @@ -2737,7 +2737,7 @@ read_keytab_file(const char *service_key_file) sk->kvno = buf[0] << 8 | buf[1]; sk->keytype = KEYTYPE_DES3_CBC_MD5; sk->length = DES3_KEY_SIZE; - sk->contents = g_memdup(buf + 2, DES3_KEY_SIZE); + sk->contents = g_memdup2(buf + 2, DES3_KEY_SIZE); g_snprintf(sk->origin, KRB_MAX_ORIG_LEN, "3DES service key file, key #%d, offset %ld", count, ftell(skf)); service_key_list = g_slist_append(service_key_list, (gpointer) sk); if (fseek(skf, newline_skip, SEEK_CUR) < 0) { diff --git a/epan/dissectors/packet-mtp3.c b/epan/dissectors/packet-mtp3.c index 569ca1d0db..f74c14ee7c 100644 --- a/epan/dissectors/packet-mtp3.c +++ b/epan/dissectors/packet-mtp3.c @@ -911,13 +911,13 @@ mtp3_stat_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, item_data = stat_tap_get_field_data(table, element, OPC_COLUMN); mtp3_addr_to_str_buf(&m3tr->addr_opc, str, 256); item_data->value.string_value = g_strdup(str); - item_data->user_data.ptr_value = g_memdup(&m3tr->addr_opc, sizeof(mtp3_tap_rec_t)); + item_data->user_data.ptr_value = g_memdup2(&m3tr->addr_opc, sizeof(mtp3_tap_rec_t)); stat_tap_set_field_data(table, element, OPC_COLUMN, item_data); item_data = stat_tap_get_field_data(table, element, DPC_COLUMN); mtp3_addr_to_str_buf(&m3tr->addr_dpc, str, 256); item_data->value.string_value = g_strdup(str); - item_data->user_data.ptr_value = g_memdup(&m3tr->addr_dpc, sizeof(mtp3_tap_rec_t)); + item_data->user_data.ptr_value = g_memdup2(&m3tr->addr_dpc, sizeof(mtp3_tap_rec_t)); stat_tap_set_field_data(table, element, DPC_COLUMN, item_data); sis = try_val_to_str(m3tr->mtp3_si_code, mtp3_service_indicator_code_short_vals); diff --git a/epan/dissectors/packet-nfs.c b/epan/dissectors/packet-nfs.c index a8ff4db9e6..e13e69d153 100644 --- a/epan/dissectors/packet-nfs.c +++ b/epan/dissectors/packet-nfs.c @@ -1069,7 +1069,7 @@ store_nfs_file_handle(nfs_fhandle_data_t *nfs_fh) fhlen = nfs_fh->len/4; /* align the file handle data */ - fhdata = (guint32 *)g_memdup(nfs_fh->fh, fhlen*4); + fhdata = (guint32 *)g_memdup2(nfs_fh->fh, fhlen*4); fhkey[0].length = 1; fhkey[0].key = &fhlen; fhkey[1].length = fhlen; @@ -1349,7 +1349,7 @@ nfs_name_snoop_fh(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int fh_of fhlen = nns->fh_length; /* align it */ - fhdata = (guint32 *)g_memdup(nns->fh, fhlen); + fhdata = (guint32 *)g_memdup2(nns->fh, fhlen); fhkey[0].length = 1; fhkey[0].key = &fhlen; fhkey[1].length = fhlen/4; diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c index 04ef072a05..4b406b8707 100644 --- a/epan/dissectors/packet-rpc.c +++ b/epan/dissectors/packet-rpc.c @@ -561,7 +561,7 @@ rpc_init_prog(int proto, guint32 prog, int ett, size_t nvers, continue; } - dissector_add_custom_table_handle("rpc.call", g_memdup(&key, sizeof(rpc_proc_info_key)), + dissector_add_custom_table_handle("rpc.call", g_memdup2(&key, sizeof(rpc_proc_info_key)), create_dissector_handle_with_name(proc->dissect_call, value->proto_id, proc->strptr)); if (proc->dissect_reply == NULL) { @@ -576,7 +576,7 @@ rpc_init_prog(int proto, guint32 prog, int ett, size_t nvers, continue; } - dissector_add_custom_table_handle("rpc.reply", g_memdup(&key, sizeof(rpc_proc_info_key)), + dissector_add_custom_table_handle("rpc.reply", g_memdup2(&key, sizeof(rpc_proc_info_key)), create_dissector_handle_with_name(proc->dissect_reply, value->proto_id, proc->strptr)); } } diff --git a/epan/dissectors/packet-smb2.c b/epan/dissectors/packet-smb2.c index 0115b53ab0..eb2a7eb877 100644 --- a/epan/dissectors/packet-smb2.c +++ b/epan/dissectors/packet-smb2.c @@ -1248,13 +1248,13 @@ static void* seskey_list_copy_cb(void *n, const void *o, size_t siz _U_) const smb2_seskey_field_t *old_rec = (const smb2_seskey_field_t *)o; new_rec->id_len = old_rec->id_len; - new_rec->id = old_rec->id ? (guchar *)g_memdup(old_rec->id, old_rec->id_len) : NULL; + new_rec->id = old_rec->id ? (guchar *)g_memdup2(old_rec->id, old_rec->id_len) : NULL; new_rec->seskey_len = old_rec->seskey_len; - new_rec->seskey = old_rec->seskey ? (guchar *)g_memdup(old_rec->seskey, old_rec->seskey_len) : NULL; + new_rec->seskey = old_rec->seskey ? (guchar *)g_memdup2(old_rec->seskey, old_rec->seskey_len) : NULL; new_rec->s2ckey_len = old_rec->s2ckey_len; - new_rec->s2ckey = old_rec->s2ckey ? (guchar *)g_memdup(old_rec->s2ckey, old_rec->s2ckey_len) : NULL; + new_rec->s2ckey = old_rec->s2ckey ? (guchar *)g_memdup2(old_rec->s2ckey, old_rec->s2ckey_len) : NULL; new_rec->c2skey_len = old_rec->c2skey_len; - new_rec->c2skey = old_rec->c2skey ? (guchar *)g_memdup(old_rec->c2skey, old_rec->c2skey_len) : NULL; + new_rec->c2skey = old_rec->c2skey ? (guchar *)g_memdup2(old_rec->c2skey, old_rec->c2skey_len) : NULL; return new_rec; } diff --git a/epan/dissectors/packet-snmp.c b/epan/dissectors/packet-snmp.c index 05fd83aa35..a70e7c60d2 100644 --- a/epan/dissectors/packet-snmp.c +++ b/epan/dissectors/packet-snmp.c @@ -1529,25 +1529,25 @@ static void set_ue_keys(snmp_ue_assoc_t* n ) { static snmp_ue_assoc_t* ue_dup(snmp_ue_assoc_t* o) { - snmp_ue_assoc_t* d = (snmp_ue_assoc_t*)g_memdup(o,sizeof(snmp_ue_assoc_t)); + snmp_ue_assoc_t* d = (snmp_ue_assoc_t*)g_memdup2(o,sizeof(snmp_ue_assoc_t)); d->user.authModel = o->user.authModel; d->user.privProtocol = o->user.privProtocol; - d->user.userName.data = (guint8 *)g_memdup(o->user.userName.data,o->user.userName.len); + d->user.userName.data = (guint8 *)g_memdup2(o->user.userName.data,o->user.userName.len); d->user.userName.len = o->user.userName.len; - d->user.authPassword.data = o->user.authPassword.data ? (guint8 *)g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL; + d->user.authPassword.data = o->user.authPassword.data ? (guint8 *)g_memdup2(o->user.authPassword.data,o->user.authPassword.len) : NULL; d->user.authPassword.len = o->user.authPassword.len; - d->user.privPassword.data = o->user.privPassword.data ? (guint8 *)g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL; + d->user.privPassword.data = o->user.privPassword.data ? (guint8 *)g_memdup2(o->user.privPassword.data,o->user.privPassword.len) : NULL; d->user.privPassword.len = o->user.privPassword.len; d->engine.len = o->engine.len; if (d->engine.len) { - d->engine.data = (guint8 *)g_memdup(o->engine.data,o->engine.len); + d->engine.data = (guint8 *)g_memdup2(o->engine.data,o->engine.len); set_ue_keys(d); } @@ -1567,24 +1567,24 @@ snmp_users_copy_cb(void* dest, const void* orig, size_t len _U_) d->priv_proto = o->priv_proto; d->user.privProtocol = priv_protos[o->priv_proto]; - d->user.userName.data = (guint8*)g_memdup(o->user.userName.data,o->user.userName.len); + d->user.userName.data = (guint8*)g_memdup2(o->user.userName.data,o->user.userName.len); d->user.userName.len = o->user.userName.len; - d->user.authPassword.data = o->user.authPassword.data ? (guint8*)g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL; + d->user.authPassword.data = o->user.authPassword.data ? (guint8*)g_memdup2(o->user.authPassword.data,o->user.authPassword.len) : NULL; d->user.authPassword.len = o->user.authPassword.len; - d->user.privPassword.data = o->user.privPassword.data ? (guint8*)g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL; + d->user.privPassword.data = o->user.privPassword.data ? (guint8*)g_memdup2(o->user.privPassword.data,o->user.privPassword.len) : NULL; d->user.privPassword.len = o->user.privPassword.len; d->engine.len = o->engine.len; if (o->engine.data) { - d->engine.data = (guint8*)g_memdup(o->engine.data,o->engine.len); + d->engine.data = (guint8*)g_memdup2(o->engine.data,o->engine.len); } - d->user.authKey.data = o->user.authKey.data ? (guint8*)g_memdup(o->user.authKey.data,o->user.authKey.len) : NULL; + d->user.authKey.data = o->user.authKey.data ? (guint8*)g_memdup2(o->user.authKey.data,o->user.authKey.len) : NULL; d->user.authKey.len = o->user.authKey.len; - d->user.privKey.data = o->user.privKey.data ? (guint8*)g_memdup(o->user.privKey.data,o->user.privKey.len) : NULL; + d->user.privKey.data = o->user.privKey.data ? (guint8*)g_memdup2(o->user.privKey.data,o->user.privKey.len) : NULL; d->user.privKey.len = o->user.privKey.len; return d; @@ -1703,17 +1703,17 @@ renew_ue_cache(void) static snmp_ue_assoc_t* localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len ) { - snmp_ue_assoc_t* n = (snmp_ue_assoc_t*)g_memdup(o,sizeof(snmp_ue_assoc_t)); + snmp_ue_assoc_t* n = (snmp_ue_assoc_t*)g_memdup2(o,sizeof(snmp_ue_assoc_t)); - n->user.userName.data = (guint8*)g_memdup(o->user.userName.data,o->user.userName.len); + n->user.userName.data = (guint8*)g_memdup2(o->user.userName.data,o->user.userName.len); n->user.authModel = o->user.authModel; - n->user.authPassword.data = (guint8*)g_memdup(o->user.authPassword.data,o->user.authPassword.len); + n->user.authPassword.data = (guint8*)g_memdup2(o->user.authPassword.data,o->user.authPassword.len); n->user.authPassword.len = o->user.authPassword.len; - n->user.privPassword.data = (guint8*)g_memdup(o->user.privPassword.data,o->user.privPassword.len); + n->user.privPassword.data = (guint8*)g_memdup2(o->user.privPassword.data,o->user.privPassword.len); n->user.privPassword.len = o->user.privPassword.len; - n->user.authKey.data = (guint8*)g_memdup(o->user.authKey.data,o->user.authKey.len); - n->user.privKey.data = (guint8*)g_memdup(o->user.privKey.data,o->user.privKey.len); - n->engine.data = (guint8*)g_memdup(engine,engine_len); + n->user.authKey.data = (guint8*)g_memdup2(o->user.authKey.data,o->user.authKey.len); + n->user.privKey.data = (guint8*)g_memdup2(o->user.privKey.data,o->user.privKey.len); + n->engine.data = (guint8*)g_memdup2(engine,engine_len); n->engine.len = engine_len; n->priv_proto = o->priv_proto; diff --git a/epan/dissectors/packet-systemd-journal.c b/epan/dissectors/packet-systemd-journal.c index 9b450552c1..bab338eb55 100644 --- a/epan/dissectors/packet-systemd-journal.c +++ b/epan/dissectors/packet-systemd-journal.c @@ -287,7 +287,7 @@ static void init_jf_to_hf_map(void) { { hf_sj_systemd_user_slice, "_SYSTEMD_USER_SLICE=" }, { 0, NULL } }; - jf_to_hf = (journal_field_hf_map*) g_memdup(jhmap, sizeof(jhmap)); + jf_to_hf = (journal_field_hf_map*) g_memdup2(jhmap, sizeof(jhmap)); } static void diff --git a/epan/dissectors/packet-zbee-nwk-gp.c b/epan/dissectors/packet-zbee-nwk-gp.c index 247f30ffed..0a5b7b0ecb 100644 --- a/epan/dissectors/packet-zbee-nwk-gp.c +++ b/epan/dissectors/packet-zbee-nwk-gp.c @@ -833,7 +833,7 @@ dissect_zbee_nwk_gp_cmd_commissioning(tvbuff_t *tvb, packet_info *pinfo, proto_t key_record.frame_num = 0; key_record.label = NULL; memcpy(key_record.key, dec_buffer, ZBEE_SEC_CONST_KEYSIZE); - zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup(&key_record, sizeof(key_record_t))); + zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup2(&key_record, sizeof(key_record_t))); payload_tvb = tvb_new_child_real_data(tvb, dec_buffer, ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE); add_new_data_source(pinfo, payload_tvb, "Decrypted security key"); @@ -849,7 +849,7 @@ dissect_zbee_nwk_gp_cmd_commissioning(tvbuff_t *tvb, packet_info *pinfo, proto_t key_record.label = NULL; key = tvb_memdup(wmem_packet_scope(), tvb, offset - ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE); memcpy(key_record.key, key, ZBEE_SEC_CONST_KEYSIZE); - zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup(&key_record, sizeof(key_record_t))); + zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup2(&key_record, sizeof(key_record_t))); } } @@ -1116,7 +1116,7 @@ dissect_zbee_nwk_gp_cmd_commissioning_reply(tvbuff_t *tvb, packet_info *pinfo, p key_record.label = NULL; key = tvb_memdup(wmem_packet_scope(), tvb, offset - ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE); memcpy(key_record.key, key, ZBEE_SEC_CONST_KEYSIZE); - zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup(&key_record, sizeof(key_record_t))); + zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup2(&key_record, sizeof(key_record_t))); } } /* Parse and display security MIC. */ @@ -1157,7 +1157,7 @@ dissect_zbee_nwk_gp_cmd_commissioning_reply(tvbuff_t *tvb, packet_info *pinfo, p key_record.frame_num = 0; key_record.label = NULL; memcpy(key_record.key, dec_buffer, ZBEE_SEC_CONST_KEYSIZE); - zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup(&key_record, sizeof(key_record_t))); + zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup2(&key_record, sizeof(key_record_t))); payload_tvb = tvb_new_child_real_data(tvb, dec_buffer, ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE); add_new_data_source(pinfo, payload_tvb, "Decrypted security key"); @@ -1931,7 +1931,7 @@ gp_init_zbee_security(void) key_record.frame_num = 0; key_record.label = g_strdup(gp_uat_key_records[i].label); memcpy(key_record.key, gp_uat_key_records[i].key, ZBEE_SEC_CONST_KEYSIZE); - zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup(&key_record, sizeof(key_record_t))); + zbee_gp_keyring = g_slist_prepend(zbee_gp_keyring, g_memdup2(&key_record, sizeof(key_record_t))); } } diff --git a/epan/dissectors/packet-zbee-security.c b/epan/dissectors/packet-zbee-security.c index ed65a59450..9b9acb71c3 100644 --- a/epan/dissectors/packet-zbee-security.c +++ b/epan/dissectors/packet-zbee-security.c @@ -192,7 +192,7 @@ static void uat_key_record_post_update(void) { key_record.frame_num = ZBEE_SEC_PC_KEY; /* means it's a user PC key */ key_record.label = g_strdup(uat_key_records[i].label); memcpy(key_record.key, key, ZBEE_SEC_CONST_KEYSIZE); - zbee_pc_keyring = g_slist_prepend(zbee_pc_keyring, g_memdup(&key_record, sizeof(key_record_t))); + zbee_pc_keyring = g_slist_prepend(zbee_pc_keyring, g_memdup2(&key_record, sizeof(key_record_t))); } } } @@ -1224,7 +1224,7 @@ void zbee_sec_add_key_to_keyring(packet_info *pinfo, const guint8 *key) if ( !nwk_keyring ) { nwk_keyring = (GSList **)g_malloc0(sizeof(GSList*)); g_hash_table_insert(zbee_table_nwk_keyring, - g_memdup(&nwk_hints->src_pan, sizeof(nwk_hints->src_pan)), nwk_keyring); + g_memdup2(&nwk_hints->src_pan, sizeof(nwk_hints->src_pan)), nwk_keyring); } if ( nwk_keyring ) { @@ -1235,7 +1235,7 @@ void zbee_sec_add_key_to_keyring(packet_info *pinfo, const guint8 *key) key_record.frame_num = pinfo->num; key_record.label = NULL; memcpy(&key_record.key, key, ZBEE_APS_CMD_KEY_LENGTH); - *nwk_keyring = g_slist_prepend(*nwk_keyring, g_memdup(&key_record, sizeof(key_record_t))); + *nwk_keyring = g_slist_prepend(*nwk_keyring, g_memdup2(&key_record, sizeof(key_record_t))); } } } diff --git a/epan/ftypes/ftype-protocol.c b/epan/ftypes/ftype-protocol.c index b3dc5328a5..a2b46c9423 100644 --- a/epan/ftypes/ftype-protocol.c +++ b/epan/ftypes/ftype-protocol.c @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -58,7 +59,7 @@ val_from_string(fvalue_t *fv, const char *s, gchar **err_msg _U_) /* Make a tvbuff from the string. We can drop the * terminating NUL. */ - private_data = (guint8 *)g_memdup(s, (guint)strlen(s)); + private_data = (guint8 *)g_memdup2(s, (guint)strlen(s)); new_tvb = tvb_new_real_data(private_data, (guint)strlen(s), (gint)strlen(s)); diff --git a/epan/funnel.c b/epan/funnel.c index 5e8cb24029..7308b34fc1 100644 --- a/epan/funnel.c +++ b/epan/funnel.c @@ -15,6 +15,7 @@ #include "config.h" #include +#include typedef struct _funnel_menu_t { char *name; @@ -106,7 +107,7 @@ void funnel_register_menu(const char *name, funnel_insert_menu(®istered_menus, m); if (menus_registered) { - funnel_menu_t* m_r = (funnel_menu_t *)g_memdup(m, sizeof *m); + funnel_menu_t* m_r = (funnel_menu_t *)g_memdup2(m, sizeof *m); m_r->name = g_strdup(name); funnel_insert_menu(&added_menus, m_r); } diff --git a/epan/maxmind_db.c b/epan/maxmind_db.c index 5b044ecdbb..4b1a2096c6 100644 --- a/epan/maxmind_db.c +++ b/epan/maxmind_db.c @@ -34,6 +34,7 @@ static mmdb_lookup_t mmdb_not_found; #include #include #include +#include // To do: // - Add RBL lookups? Along with the "is this a spammer" information that most RBL databases @@ -616,7 +617,7 @@ gboolean maxmind_db_lookup_process(void) mmdb_response_t *response; while (mmdbr_response_q && (response = (mmdb_response_t *) g_async_queue_try_pop(mmdbr_response_q)) != NULL) { - mmdb_lookup_t *mmdb_val = (mmdb_lookup_t *) g_memdup(&response->mmdb_val, sizeof(mmdb_lookup_t)); + mmdb_lookup_t *mmdb_val = (mmdb_lookup_t *) g_memdup2(&response->mmdb_val, sizeof(mmdb_lookup_t)); if (response->mmdb_val.country_iso) { char *country_iso = (char *) response->mmdb_val.country_iso; mmdb_val->country_iso = chunkify_string(country_iso); diff --git a/epan/packet.h b/epan/packet.h index d024e869f6..96f64e8722 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -22,6 +22,7 @@ #include "tfs.h" #include "unit_strings.h" #include "ws_symbol_export.h" +#include "wsutil/glib-compat.h" #ifdef __cplusplus extern "C" { diff --git a/epan/secrets.c b/epan/secrets.c index 200f032df6..13717d7761 100644 --- a/epan/secrets.c +++ b/epan/secrets.c @@ -16,6 +16,7 @@ #include "secrets.h" #include +#include #include #ifdef HAVE_LIBGNUTLS @@ -135,7 +136,7 @@ privkey_hash_table_new(void) static void rsa_privkey_add(const cert_key_id_t *key_id, gnutls_privkey_t pkey) { - void *ht_key = g_memdup(key_id->key_id, sizeof(cert_key_id_t)); + void *ht_key = g_memdup2(key_id->key_id, sizeof(cert_key_id_t)); const guint32 *dw = (const guint32 *)key_id->key_id; g_hash_table_insert(rsa_privkeys, ht_key, pkey); g_debug("Adding RSA private, Key ID %08x%08x%08x%08x%08x", g_htonl(dw[0]), @@ -639,7 +640,7 @@ secrets_rsa_decrypt(const cert_key_id_t *key_id, const guint8 *encr, int encr_le ret = gnutls_privkey_decrypt_data(pkey, 0, &ciphertext, &plain); if (ret == 0) { - *out = (guint8 *)g_memdup(plain.data, plain.size); + *out = (guint8 *)g_memdup2(plain.data, plain.size); *out_len = plain.size; gnutls_free(plain.data); } diff --git a/epan/tvbuff_zlib.c b/epan/tvbuff_zlib.c index 6d07bffccf..d8b917d5c5 100644 --- a/epan/tvbuff_zlib.c +++ b/epan/tvbuff_zlib.c @@ -14,6 +14,7 @@ #include #include +#include #ifdef HAVE_ZLIB #define ZLIB_CONST @@ -114,12 +115,12 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen) * This is ugly workaround for bug #6480 * (https://gitlab.com/wireshark/wireshark/-/issues/6480) * - * g_memdup(..., 0) returns NULL (g_malloc(0) also) + * g_memdup2(..., 0) returns NULL (g_malloc(0) also) * when uncompr is NULL logic below doesn't create tvb * which is later interpreted as decompression failed. */ uncompr = (guint8 *)((bytes_pass || err != Z_STREAM_END) ? - g_memdup(strmbuf, bytes_pass) : + g_memdup2(strmbuf, bytes_pass) : g_strdup("")); } else { guint8 *new_data = (guint8 *)g_malloc0(bytes_out + bytes_pass); diff --git a/epan/uat.h b/epan/uat.h index 8876b0e562..5116b4e8e5 100644 --- a/epan/uat.h +++ b/epan/uat.h @@ -503,12 +503,12 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, */ #define UAT_BUFFER_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \ static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\ - char* new_buf = len ? (char *)g_memdup(buf,len) : NULL; \ + char* new_buf = len ? (char *)g_memdup2(buf,len) : NULL; \ g_free((((rec_t*)rec)->ptr_element)); \ (((rec_t*)rec)->ptr_element) = new_buf; \ (((rec_t*)rec)->len_element) = len; } \ static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\ - *out_ptr = ((rec_t*)rec)->ptr_element ? (char*)g_memdup(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : g_strdup(""); \ + *out_ptr = ((rec_t*)rec)->ptr_element ? (char*)g_memdup2(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : g_strdup(""); \ *out_len = ((rec_t*)rec)->len_element; } #define UAT_FLD_BUFFER(basename,field_name,title,desc) \ diff --git a/epan/wslua/wslua_byte_array.c b/epan/wslua/wslua_byte_array.c index 5a5455b463..050a17ad7e 100644 --- a/epan/wslua/wslua_byte_array.c +++ b/epan/wslua/wslua_byte_array.c @@ -19,7 +19,6 @@ #include "wslua.h" - /* WSLUA_CONTINUE_MODULE Tvb */ @@ -372,7 +371,7 @@ WSLUA_METHOD ByteArray_tvb (lua_State *L) { return 0; } - data = (guint8 *)g_memdup(ba->data, ba->len); + data = (guint8 *)g_memdup2(ba->data, ba->len); tvb = (Tvb)g_malloc(sizeof(struct _wslua_tvb)); tvb->ws_tvb = tvb_new_child_real_data(lua_tvb, data, ba->len,ba->len); diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c index a5fb402a97..37b0955244 100644 --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -666,7 +666,7 @@ WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) { fh->finfo.default_file_extension = NULL; fh->finfo.additional_file_extensions = NULL; fh->finfo.writing_must_seek = FALSE; - supported_blocks = (struct supported_block_type *)g_memdup(&block_type_proto, sizeof block_type_proto); + supported_blocks = (struct supported_block_type *)g_memdup2(&block_type_proto, sizeof block_type_proto); /* * Add a list of options to the seciton block, interface block, and * packet block, so the file handler can indicate comment support. @@ -678,7 +678,7 @@ WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) { case WTAP_BLOCK_IF_ID_AND_INFO: case WTAP_BLOCK_PACKET: supported_blocks[i].num_supported_options = OPTION_TYPES_SUPPORTED(option_type_proto); - supported_blocks[i].supported_options = (struct supported_option_type *)g_memdup(&option_type_proto, sizeof option_type_proto); + supported_blocks[i].supported_options = (struct supported_option_type *)g_memdup2(&option_type_proto, sizeof option_type_proto); break; default: diff --git a/sharkd_session.c b/sharkd_session.c index d0ec9c79f6..6e578cb4ad 100644 --- a/sharkd_session.c +++ b/sharkd_session.c @@ -4002,10 +4002,10 @@ sharkd_session_packet_download_tap_rtp_cb(void *tapdata, packet_info *pinfo, epa rtp_packet_t *rtp_packet; rtp_packet = g_new0(rtp_packet_t, 1); - rtp_packet->info = (struct _rtp_info *) g_memdup(rtp_info, sizeof(struct _rtp_info)); + rtp_packet->info = (struct _rtp_info *) g_memdup2(rtp_info, sizeof(struct _rtp_info)); if (rtp_info->info_all_data_present && rtp_info->info_payload_len != 0) - rtp_packet->payload_data = (guint8 *) g_memdup(&(rtp_info->info_data[rtp_info->info_payload_offset]), rtp_info->info_payload_len); + rtp_packet->payload_data = (guint8 *) g_memdup2(&(rtp_info->info_data[rtp_info->info_payload_offset]), rtp_info->info_payload_len); if (!req_rtp->packets) req_rtp->start_time = nstime_to_sec(&pinfo->abs_ts); diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp index 324d9f20a5..4c57d7404f 100644 --- a/ui/qt/rtp_audio_stream.cpp +++ b/ui/qt/rtp_audio_stream.cpp @@ -129,9 +129,10 @@ void RtpAudioStream::addRtpPacket(const struct _packet_info *pinfo, const struct if (!rtp_info) return; rtp_packet_t *rtp_packet = g_new0(rtp_packet_t, 1); - rtp_packet->info = (struct _rtp_info *) g_memdup(rtp_info, sizeof(struct _rtp_info)); + rtp_packet->info = (struct _rtp_info *) g_memdup2(rtp_info, sizeof(struct _rtp_info)); if (rtp_info->info_all_data_present && (rtp_info->info_payload_len != 0)) { - rtp_packet->payload_data = (guint8 *) g_memdup(&(rtp_info->info_data[rtp_info->info_payload_offset]), rtp_info->info_payload_len); + rtp_packet->payload_data = (guint8 *) g_memdup2(&(rtp_info->info_data[rtp_info->info_payload_offset]), + rtp_info->info_payload_len); } if (rtp_packets_.size() < 1) { // First packet diff --git a/ui/voip_calls.c b/ui/voip_calls.c index 8eea6cd9a1..7aada662aa 100644 --- a/ui/voip_calls.c +++ b/ui/voip_calls.c @@ -54,6 +54,8 @@ #include "ui/ws_ui_util.h" #include "ui/voip_calls.h" +#include "wsutil/glib-compat.h" + #define DUMP_PTR1(p) printf("#=> %p\n",(void *)p) #define DUMP_PTR2(p) printf("==> %p\n",(void *)p) @@ -2079,7 +2081,7 @@ h225_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt, tmp_h323info = (h323_calls_info_t *)callsinfo->prot_info; g_assert(tmp_h323info != NULL); - tmp_h323info->guid = (e_guid_t *)g_memdup(&pi->guid, sizeof pi->guid); + tmp_h323info->guid = (e_guid_t *)g_memdup2(&pi->guid, sizeof pi->guid); /* DUMP_PTR1(tmp_h323info->guid); */ clear_address(&tmp_h323info->h225SetupAddr); diff --git a/wiretap/erf.c b/wiretap/erf.c index 878cfc1c3b..672661532a 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -30,6 +30,7 @@ #include #include +#include #include "wtap-int.h" #include "file_wrappers.h" @@ -3253,7 +3254,7 @@ static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_h * before the interface information, as we associate them to interface * data. */ - post_list = g_list_append(post_list, g_memdup(&state, sizeof(struct erf_meta_read_state))); + post_list = g_list_append(post_list, g_memdup2(&state, sizeof(struct erf_meta_read_state))); break; case ERF_META_SECTION_SOURCE: case ERF_META_SECTION_DNS: diff --git a/wiretap/k12.c b/wiretap/k12.c index ece5b697db..d9ee211c92 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -21,6 +21,7 @@ #include "k12.h" #include +#include /* * See @@ -1060,8 +1061,8 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) { g_free(rec); return WTAP_OPEN_ERROR; } - rec->input_name = (gchar *)g_memdup(read_buffer + K12_SRCDESC_HWPART + hwpart_len, name_len); - rec->stack_file = (gchar *)g_memdup(read_buffer + K12_SRCDESC_HWPART + hwpart_len + name_len, stack_len); + rec->input_name = (gchar *)g_memdup2(read_buffer + K12_SRCDESC_HWPART + hwpart_len, name_len); + rec->stack_file = (gchar *)g_memdup2(read_buffer + K12_SRCDESC_HWPART + hwpart_len + name_len, stack_len); ascii_strdown_inplace (rec->stack_file); diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 0ab01055c8..48ce5f707b 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -23,6 +23,7 @@ #include #include +#include #include "wtap-int.h" #include "file_wrappers.h" @@ -1662,7 +1663,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, wblock->rec->packet_verdict = g_ptr_array_new_with_free_func((GDestroyNotify) g_bytes_unref); } - option_content_copy = g_memdup(option_content, oh->option_length); + option_content_copy = g_memdup2(option_content, oh->option_length); /* For Linux XDP and TC we might need to byte swap */ if (section_info->byte_swapped && diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c index 1e3e3ec798..b887b4bc14 100644 --- a/wiretap/wtap_opttypes.c +++ b/wiretap/wtap_opttypes.c @@ -16,6 +16,8 @@ #include "wtap-int.h" #include "pcapng_module.h" +#include + #if 0 #define wtap_debug(...) g_warning(__VA_ARGS__) #else @@ -773,7 +775,7 @@ static if_filter_opt_t if_filter_dup(if_filter_opt_t* filter_src) filter_dest.data.bpf_prog.bpf_prog_len = filter_src->data.bpf_prog.bpf_prog_len; filter_dest.data.bpf_prog.bpf_prog = - (wtap_bpf_insn_t *)g_memdup(filter_src->data.bpf_prog.bpf_prog, + (wtap_bpf_insn_t *)g_memdup2(filter_src->data.bpf_prog.bpf_prog, filter_src->data.bpf_prog.bpf_prog_len * sizeof (wtap_bpf_insn_t)); break; @@ -1019,7 +1021,7 @@ static void dsb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block) dst->secrets_type = src->secrets_type; dst->secrets_len = src->secrets_len; g_free(dst->secrets_data); - dst->secrets_data = (guint8 *)g_memdup(src->secrets_data, src->secrets_len); + dst->secrets_data = (guint8 *)g_memdup2(src->secrets_data, src->secrets_len); } void wtap_opttypes_initialize(void) diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 207b1dce81..1d57e13ef0 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -66,6 +66,7 @@ set(WSUTIL_PUBLIC_HEADERS unicode-utils.h utf8_entities.h ws_cpuid.h + glib-compat.h ws_mempbrk.h ws_mempbrk_int.h ws_pipe.h @@ -118,6 +119,7 @@ set(WSUTIL_COMMON_FILES time_util.c type_util.c unicode-utils.c + glib-compat.c ws_mempbrk.c ws_pipe.c wsgcrypt.c diff --git a/wsutil/glib-compat.c b/wsutil/glib-compat.c new file mode 100644 index 0000000000..6a0afa28d5 --- /dev/null +++ b/wsutil/glib-compat.c @@ -0,0 +1,42 @@ +/* +* Provide some functions that are not present in older +* GLIB versions (down to 2.22) +* +* Wireshark - Network traffic analyzer +* By Gerald Combs +* Copyright 1998 Gerald Combs +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include "config.h" + +#include + +#include "glib-compat.h" +#if !GLIB_CHECK_VERSION(2, 68, 0) +/** +* g_memdup2: +* mem: the memory to copy +* byte_size: the number of bytes to copy. +* +* Allocates byte_size bytes of memory, and copies byte_size bytes into it from mem . If mem is NULL it returns NULL. +* +* This replaces g_memdup(), which was prone to integer overflows when converting the argument from a gsize to a guint. +* +* Since: 2.68 +**/ +gpointer +g_memdup2(gconstpointer mem, gsize byte_size) +{ + gpointer new_mem; + + if (mem && byte_size != 0) { + new_mem = g_malloc(byte_size); + memcpy(new_mem, mem, byte_size); + } + else + new_mem = NULL; + + return new_mem; +} +#endif diff --git a/wsutil/glib-compat.h b/wsutil/glib-compat.h new file mode 100644 index 0000000000..788f5fb41c --- /dev/null +++ b/wsutil/glib-compat.h @@ -0,0 +1,31 @@ +/* glib-compat.h +* Definitions to provide some functions that are not present in older +* GLIB versions (down to 2.22) +* +* Wireshark - Network traffic analyzer +* By Gerald Combs +* Copyright 1998 Gerald Combs +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef GLIB_COMPAT_H +#define GLIB_COMPAT_H + +#include "ws_symbol_export.h" +#include "ws_attributes.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if !GLIB_CHECK_VERSION(2, 68, 0) +WS_DLL_PUBLIC gpointer g_memdup2(gconstpointer mem, gsize byte_size); +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GLIB_COMPAT_H */