aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-05-04 23:13:48 +0200
committerDario Lombardo <lomato@gmail.com>2018-05-05 16:44:32 +0000
commit4e6d4b94e2e7f56ac1e1144714cb6acd926291bd (patch)
tree58246e8f099e11c03cbc1f2c811e4f46932de0c0
parent84c200af93d10796dfc49fb9112feca17577e8c2 (diff)
zbee-security: fix keyring memleaks
If zbee_security_parse_key fails, the cloned label was leaked. Updating The keyring contents was also leaked. Found by Clang Static Analyzer. Change-Id: I5ef8e890f5b2b37d562b7f7a85b046bea9559841 Reviewed-on: https://code.wireshark.org/review/27347 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <lomato@gmail.com>
-rw-r--r--epan/dissectors/packet-zbee-security.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/epan/dissectors/packet-zbee-security.c b/epan/dissectors/packet-zbee-security.c
index f5f66268b2..dab9ddb73b 100644
--- a/epan/dissectors/packet-zbee-security.c
+++ b/epan/dissectors/packet-zbee-security.c
@@ -166,6 +166,14 @@ static void uat_key_record_free_cb(void*r) {
g_free(key->label);
}
+static void zbee_free_key_record(gpointer ptr)
+{
+ key_record_t *k = (key_record_t *)ptr;
+
+ g_free(k->label);
+ g_free(k);
+}
+
static void uat_key_record_post_update(void) {
guint i;
key_record_t key_record;
@@ -173,15 +181,15 @@ static void uat_key_record_post_update(void) {
/* empty the key ring */
if (zbee_pc_keyring) {
- g_slist_free(zbee_pc_keyring);
+ g_slist_free_full(zbee_pc_keyring, zbee_free_key_record);
zbee_pc_keyring = NULL;
}
/* Load the pre-configured slist from the UAT. */
for (i=0; (uat_key_records) && (i<num_uat_key_records) ; i++) {
- 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);
if (zbee_security_parse_key(uat_key_records[i].string, key, uat_key_records[i].byte_order)) {
+ 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)));
}