wsutils: add local implementation of g_memdup2.

g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
This commit is contained in:
Dario Lombardo 2021-03-23 16:41:54 +01:00 committed by Wireshark GitLab Utility
parent e6df130762
commit ea929d6401
41 changed files with 197 additions and 105 deletions

View File

@ -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

View File

@ -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);

View File

@ -16,6 +16,7 @@
#include <wsutil/wsgcrypt.h>
#include <wsutil/crc32.h>
#include <wsutil/pint.h>
#include <wsutil/glib-compat.h>
#include <epan/proto.h> /* for DISSECTOR_ASSERT. */
#include <epan/tvbuff.h>
@ -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;

View File

@ -22,6 +22,7 @@
#include <ftypes/ftypes-int.h>
#include <epan/uat-int.h>
#include <epan/proto.h>
#include <wsutil/glib-compat.h>
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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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

View File

@ -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)));
}
}

View File

@ -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)));
}
}
}

View File

@ -12,6 +12,7 @@
#include <epan/strutil.h>
#include <epan/to_str-int.h>
#include <string.h>
#include <wsutil/glib-compat.h>
#include <epan/exceptions.h>
@ -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));

View File

@ -15,6 +15,7 @@
#include "config.h"
#include <epan/funnel.h>
#include <wsutil/glib-compat.h>
typedef struct _funnel_menu_t {
char *name;
@ -106,7 +107,7 @@ void funnel_register_menu(const char *name,
funnel_insert_menu(&registered_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);
}

View File

@ -34,6 +34,7 @@ static mmdb_lookup_t mmdb_not_found;
#include <wsutil/filesystem.h>
#include <wsutil/ws_pipe.h>
#include <wsutil/strtoi.h>
#include <wsutil/glib-compat.h>
// 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);

View File

@ -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" {

View File

@ -16,6 +16,7 @@
#include "secrets.h"
#include <wiretap/wtap.h>
#include <wsutil/glib-compat.h>
#include <string.h>
#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);
}

View File

@ -14,6 +14,7 @@
#include <glib.h>
#include <string.h>
#include <wsutil/glib-compat.h>
#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);

View File

@ -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) \

View File

@ -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);

View File

@ -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:

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -30,6 +30,7 @@
#include <wsutil/crc32.h>
#include <wsutil/strtoi.h>
#include <wsutil/glib-compat.h>
#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:

View File

@ -21,6 +21,7 @@
#include "k12.h"
#include <wsutil/str_util.h>
#include <wsutil/glib-compat.h>
/*
* 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);

View File

@ -23,6 +23,7 @@
#include <wsutil/ws_printf.h>
#include <wsutil/strtoi.h>
#include <wsutil/glib-compat.h>
#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 &&

View File

@ -16,6 +16,8 @@
#include "wtap-int.h"
#include "pcapng_module.h"
#include <wsutil/glib-compat.h>
#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)

View File

@ -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

42
wsutil/glib-compat.c Normal file
View File

@ -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 <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <glib.h>
#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

31
wsutil/glib-compat.h Normal file
View File

@ -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 <gerald@wireshark.org>
* 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 <glib.h>
#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 */