From b2c26771b5613be707d15f7d00f066d946b8eea1 Mon Sep 17 00:00:00 2001 From: mjentsch Date: Sat, 13 Dec 2014 16:09:09 +0100 Subject: [PATCH] Fix segmentation fault on chat creation update Check for null-pointer before passing hash table content to strcmp --- tgp-2prpl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tgp-2prpl.c b/tgp-2prpl.c index e85be99..22bc976 100644 --- a/tgp-2prpl.c +++ b/tgp-2prpl.c @@ -105,7 +105,11 @@ static PurpleChat *blist_find_chat_by_hasht_cond(PurpleConnection *gc, } static int hasht_cmp_id(GHashTable *hasht, void *data) { - return !strcmp(g_hash_table_lookup(hasht, "id"), *((char **)data)); + gpointer id = g_hash_table_lookup(hasht, "id"); + if (!id || !data) { + return 0; + } + return !strcmp(id, ((char *)data)); } @@ -248,7 +252,7 @@ PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat) { PurpleChat *p2tgl_chat_find (struct tgl_state *TLS, tgl_peer_id_t id) { char *name = peer_strdup_id(id); - PurpleChat *c = blist_find_chat_by_hasht_cond(tg_get_conn(TLS), hasht_cmp_id, &name); + PurpleChat *c = blist_find_chat_by_hasht_cond(tg_get_conn(TLS), hasht_cmp_id, name); g_free(name); return c; }