jabber: Fix URI handler potentially using NULL GHashTable

Fri, 23 Nov 2018 15:57:21 -0600

author
Mike Ruprecht <cmaiku@gmail.com>
date
Fri, 23 Nov 2018 15:57:21 -0600
changeset 39306
cc872191c956
parent 39305
0852c82372c3
child 39308
9796e578dbf7

jabber: Fix URI handler potentially using NULL GHashTable

There are a few instances in the Jabber prpl's uri-handler callback
which could potentially attempt to lookup values in a NULL GHashTable
pointer. It doesn't crash, but it does spit out a warning. This patch
guards against such usage, silencing such warnings.

libpurple/protocols/jabber/jabber.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/jabber/jabber.c	Fri Nov 02 19:18:24 2018 -0500
+++ b/libpurple/protocols/jabber/jabber.c	Fri Nov 23 15:57:21 2018 -0600
@@ -3789,7 +3789,7 @@
 		gpointer user_data)
 {
 	PurpleProtocol *protocol = (PurpleProtocol *)user_data;
-	char *acct_id = params ? g_hash_table_lookup(params, "account") : NULL;
+	const gchar *acct_id = NULL;
 	PurpleAccount *acct;
 
 	g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), FALSE);
@@ -3797,6 +3797,10 @@
 	if (g_ascii_strcasecmp(proto, "xmpp"))
 		return FALSE;
 
+ 	if (params != NULL) {
+		acct_id = g_hash_table_lookup(params, "account");
+	}
+
 	acct = find_acct(protocol->id, acct_id);
 
 	if (!acct)
@@ -3805,11 +3809,17 @@
 	/* xmpp:romeo@montague.net?message;subject=Test%20Message;body=Here%27s%20a%20test%20message */
 	/* params is NULL if the URI has no '?' (or anything after it) */
 	if (!params || g_hash_table_lookup_extended(params, "message", NULL, NULL)) {
-		char *body = g_hash_table_lookup(params, "body");
 		if (user && *user) {
 			PurpleIMConversation *im =
 					purple_im_conversation_new(acct, user);
+			const gchar *body = NULL;
+
 			purple_conversation_present(PURPLE_CONVERSATION(im));
+
+			if (params != NULL) {
+				body = g_hash_table_lookup(params, "body");
+			}
+
 			if (body && *body)
 				purple_conversation_send_confirm(PURPLE_CONVERSATION(im), body);
 			return TRUE;

mercurial