diff options
author | Moshe Kaplan <me@moshekaplan.com> | 2020-12-20 21:30:28 -0500 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2020-12-22 14:56:38 +0000 |
commit | e16166a74cca1d66e2c302e257cf94aebb380599 (patch) | |
tree | 8834b4b8390fca83dd7bc1b4b9e6a7bb276e1d7e /epan/dissectors/packet-radius.c | |
parent | 7b27b444cbd94853b399da770e0dad4b91ef23ac (diff) |
Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing
occurrences of `g_malloc()` and `wmem_alloc()` with
`g_new()` and `wmem_new()`, to improve the
readability of Wireshark's code, and
occurrences of
`g_malloc(sizeof(struct myobj) * foo)`
with
`g_new(struct myobj, foo)`
to prevent integer overflows
Also fixes all existing occurrences across
the codebase.
Diffstat (limited to 'epan/dissectors/packet-radius.c')
-rw-r--r-- | epan/dissectors/packet-radius.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c index b745619407..6a88193582 100644 --- a/epan/dissectors/packet-radius.c +++ b/epan/dissectors/packet-radius.c @@ -1677,7 +1677,7 @@ dissect_attribute_value_pairs(proto_tree *tree, packet_info *pinfo, tvbuff_t *tv if (avp_vsa_flags & 0x80) { if (!vsa_buffer) { - vsa_buffer = (radius_vsa_buffer *)g_malloc(sizeof(radius_vsa_buffer)); + vsa_buffer = g_new(radius_vsa_buffer, 1); vsa_buffer->key.vendor_id = vendor_id; vsa_buffer->key.vsa_type = avp_vsa_type; vsa_buffer->len = avp_vsa_len; @@ -2482,7 +2482,7 @@ radius_register_avp_dissector(guint32 vendor_id, guint32 _attribute_id, radius_a vendor = (radius_vendor_info_t *)g_hash_table_lookup(dict->vendors_by_id, GUINT_TO_POINTER(vendor_id)); if (!vendor) { - vendor = (radius_vendor_info_t *)g_malloc(sizeof(radius_vendor_info_t)); + vendor = g_new(radius_vendor_info_t, 1); vendor->name = g_strdup_printf("%s-%u", enterprises_lookup(vendor_id, "Unknown"), @@ -2508,7 +2508,7 @@ radius_register_avp_dissector(guint32 vendor_id, guint32 _attribute_id, radius_a } if (!dictionary_entry) { - dictionary_entry = (radius_attr_info_t *)g_malloc(sizeof(radius_attr_info_t)); + dictionary_entry = g_new(radius_attr_info_t, 1); dictionary_entry->name = g_strdup_printf("Unknown-Attribute-%u", attribute_id.value); dictionary_entry->code = attribute_id; @@ -2849,7 +2849,7 @@ proto_register_radius(void) radius_tap = register_tap("radius"); proto_register_prefix("radius", register_radius_fields); - dict = (radius_dictionary_t *)g_malloc(sizeof(radius_dictionary_t)); + dict = g_new(radius_dictionary_t, 1); /* * IDs map to names and vice versa. The attribute and vendor is stored * only once, but referenced by both name and ID mappings. |