[asterisk-commits] dvossel: branch dvossel/gtalk_fixup r291543 - /team/dvossel/gtalk_fixup/chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 13 15:54:53 CDT 2010


Author: dvossel
Date: Wed Oct 13 15:54:48 2010
New Revision: 291543

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=291543
Log:
Cleaned up some unsafe string cmp logic.

Modified:
    team/dvossel/gtalk_fixup/channels/chan_gtalk.c

Modified: team/dvossel/gtalk_fixup/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/gtalk_fixup/channels/chan_gtalk.c?view=diff&rev=291543&r1=291542&r2=291543
==============================================================================
--- team/dvossel/gtalk_fixup/channels/chan_gtalk.c (original)
+++ team/dvossel/gtalk_fixup/channels/chan_gtalk.c Wed Oct 13 15:54:48 2010
@@ -788,8 +788,10 @@
 	ast_debug(1, "The client is %s\n", client->name);
 	/* Make sure our new call doesn't exist yet */
 	for (tmp = client->p; tmp; tmp = tmp->next) {
-		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) || !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
+			(iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
 			break;
+		}
 	}
 	from = iks_find_attrib(pak->x, "to");
 	if (!from) {
@@ -1239,6 +1241,7 @@
 	char *from = NULL;
 	char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ];
 	int peernoncodeccapability;
+	char *sid;
 
 	/* Make sure our new call doesn't exist yet */
 	from = iks_find_attrib(pak->x,"to");
@@ -1247,7 +1250,8 @@
 	}
 
 	while (tmp) {
-		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) || !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid)) {
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
+			(iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
 			ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
 			gtalk_response(client, from, pak, "out-of-order", NULL);
 			return -1;
@@ -1265,7 +1269,12 @@
 		}
 	}
 
-	p = gtalk_alloc(client, from, pak->from->full, iks_find_attrib(pak->query, "id"));
+	if (!(sid = iks_find_attrib(pak->query, "id"))) {
+		ast_log(LOG_WARNING, "Received Initiate without id attribute. Can not start call.\n");
+		return -1;
+	}
+
+	p = gtalk_alloc(client, from, pak->from->full, sid);
 	if (!p) {
 		ast_log(LOG_WARNING, "Unable to allocate gtalk structure!\n");
 		return -1;
@@ -1287,21 +1296,24 @@
 
 	ast_mutex_lock(&p->lock);
 	ast_copy_string(p->them, pak->from->full, sizeof(p->them));
-	if (iks_find_attrib(pak->query, "id")) {
-		ast_copy_string(p->sid, iks_find_attrib(pak->query, "id"),
-				sizeof(p->sid));
-	}
+	ast_copy_string(p->sid, sid, sizeof(p->sid));
 
 	/* codec points to the first <payload-type/> tag */
 	codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
 
 	while (codec) {
+		char *codec_id = iks_find_attrib(codec, "id");
+		char *codec_name = iks_find_attrib(codec, "name");
+		if (!codec_id || !codec_name) {
+			codec = iks_next_tag(codec);
+			continue;
+		}
 		if (!strcmp(iks_name(codec), "vid:payload-type") && p->vrtp) {
-			ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->vrtp), p->vrtp, atoi(iks_find_attrib(codec, "id")));
-			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->vrtp), p->vrtp, atoi(iks_find_attrib(codec, "id")), "video", iks_find_attrib(codec, "name"), 0);
+			ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->vrtp), p->vrtp, atoi(codec_id));
+			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->vrtp), p->vrtp, atoi(codec_id), "video", codec_name, 0);
 		} else {
-			ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")));
-			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+			ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(codec_id));
+			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(codec_id), "audio", codec_name, 0);
 		}
 		codec = iks_next_tag(codec);
 	}
@@ -1453,7 +1465,8 @@
 	}
 
 	for (tmp = client->p; tmp; tmp = tmp->next) {
-		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) || !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid)) {
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
+			(iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
 			p = tmp;
 			break;
 		}
@@ -1476,30 +1489,35 @@
 			newcandidate = ast_calloc(1, sizeof(*newcandidate));
 			if (!newcandidate)
 				return 0;
-			ast_copy_string(newcandidate->name, iks_find_attrib(traversenodes, "name"),
-							sizeof(newcandidate->name));
-			ast_copy_string(newcandidate->ip, iks_find_attrib(traversenodes, "address"),
-							sizeof(newcandidate->ip));
+			ast_copy_string(newcandidate->name,
+				S_OR(iks_find_attrib(traversenodes, "name"), ""),
+				sizeof(newcandidate->name));
+			ast_copy_string(newcandidate->ip,
+				S_OR(iks_find_attrib(traversenodes, "address"), ""),
+				sizeof(newcandidate->ip));
 			newcandidate->port = atoi(iks_find_attrib(traversenodes, "port"));
-			ast_copy_string(newcandidate->username, iks_find_attrib(traversenodes, "username"),
-							sizeof(newcandidate->username));
-			ast_copy_string(newcandidate->password, iks_find_attrib(traversenodes, "password"),
-							sizeof(newcandidate->password));
+			ast_copy_string(newcandidate->username,
+				S_OR(iks_find_attrib(traversenodes, "username"), ""),
+				sizeof(newcandidate->username));
+			ast_copy_string(newcandidate->password,
+				S_OR(iks_find_attrib(traversenodes, "password"), ""),
+				sizeof(newcandidate->password));
 			newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference"));
-			if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "udp"))
+			if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "protocol"), ""), "udp"))
 				newcandidate->protocol = AJI_PROTOCOL_UDP;
-			if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "ssltcp"))
+			if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "protocol"), ""), "ssltcp"))
 				newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
 
-			if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "stun"))
+			if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "stun"))
 				newcandidate->type = AJI_CONNECT_STUN;
-			if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "local"))
+			if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "local"))
 				newcandidate->type = AJI_CONNECT_LOCAL;
-			if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "relay"))
+			if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "relay"))
 				newcandidate->type = AJI_CONNECT_RELAY;
-			ast_copy_string(newcandidate->network, iks_find_attrib(traversenodes, "network"),
-							sizeof(newcandidate->network));
-			newcandidate->generation = atoi(iks_find_attrib(traversenodes, "generation"));
+			ast_copy_string(newcandidate->network,
+				S_OR(iks_find_attrib(traversenodes, "network"), ""),
+				sizeof(newcandidate->network));
+			newcandidate->generation = atoi(S_OR(iks_find_attrib(traversenodes, "generation"), "0"));
 			newcandidate->next = NULL;
 
 			newcandidate->next = p->theircandidates;
@@ -1514,8 +1532,8 @@
 	receipt = iks_new("iq");
 	iks_insert_attrib(receipt, "type", "result");
 	iks_insert_attrib(receipt, "from", from);
-	iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
-	iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
+	iks_insert_attrib(receipt, "to", S_OR(iks_find_attrib(pak->x, "from"), ""));
+	iks_insert_attrib(receipt, "id", S_OR(iks_find_attrib(pak->x, "id"), ""));
 	ast_aji_send(c, receipt);
 
 	iks_delete(receipt);
@@ -1961,8 +1979,12 @@
 	struct gtalk *client = ASTOBJ_REF((struct gtalk *) data);
 	int res;
 
-	if (iks_find_attrib(pak->x, "type") && !strcmp(iks_find_attrib (pak->x, "type"),"error")) {
+	if (!strcmp(S_OR(iks_find_attrib(pak->x, "type"), ""), "error")) {
 		ast_log(LOG_NOTICE, "Remote peer reported an error, trying to establish the call anyway\n");
+	}
+
+	if (ast_strlen_zero(iks_find_attrib(pak->query, "type"))) {
+		ast_log(LOG_NOTICE, "No attribute \"type\" found.  Ignoring message.\n");
 	} else if (!strcmp(iks_find_attrib(pak->query, "type"), "initiate")) {
 		/* New call */
 		gtalk_newcall(client, pak);




More information about the asterisk-commits mailing list