From fdd39eae5850e699aac2609d5baf41e0945929a0 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Mon, 16 Jul 2012 19:14:29 +0000
Subject: [PATCH] Fix an issue where a service discovery request could crash
 Asterisk.

A server sending a service discovery request to us may or may not put a from attribute in the message. If the from attribute is present use it in the to attribute for the result. If the from attribute is not present do not add a to attribute.

(issue ASTERISK-16203)
Reported by: wubbla


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370126 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 res/res_xmpp.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index 546243c7b5..91be7afbdd 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -2211,7 +2211,11 @@ static int xmpp_client_service_discovery_get_hook(void *data, ikspak *pak)
 	}
 
 	iks_insert_attrib(iq, "from", client->jid->full);
-	iks_insert_attrib(iq, "to", pak->from->full);
+
+	if (pak->from) {
+		iks_insert_attrib(iq, "to", pak->from->full);
+	}
+
 	iks_insert_attrib(iq, "type", "result");
 	iks_insert_attrib(iq, "id", pak->id);
 	iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
@@ -3037,8 +3041,11 @@ static int xmpp_pak_presence(struct ast_xmpp_client *client, struct ast_xmpp_cli
 	}
 
 	if (!(buddy = ao2_find(client->buddies, pak->from->partial, OBJ_KEY))) {
-		ast_log(LOG_WARNING, "Received presence information about '%s' despite not having them in roster on client '%s'\n",
-			pak->from->partial, client->name);
+		/* Only output the message if it is not about us */
+		if (strcmp(client->jid->partial, pak->from->partial)) {
+			ast_log(LOG_WARNING, "Received presence information about '%s' despite not having them in roster on client '%s'\n",
+				pak->from->partial, client->name);
+		}
 		return 0;
 	}
 
-- 
GitLab