Skip to content
Snippets Groups Projects
Commit bade6867 authored by Philippe Sultan's avatar Philippe Sultan
Browse files

Merged revisions 79665 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r79665 | phsultan | 2007-08-16 11:37:10 +0200 (Thu, 16 Aug 2007) | 21 lines

A fix for two critical problems detected while working with Daniel
McKeehan in issue #10184. 

Upon priority change, the resource list is not NULL terminated when
moving an item to the end of the list. This makes Asterisk endlessy
loop whenever it needs to read the list. Jids with different resource and
priority values, like in Gmail's and GoogleTalk's jabber clients put
that problem in evidence.

Upon reception of a 'from' attribute with an empty resource string,
Asterisk crashes when trying to access the found->cap pointer if the
resource list for the given buddy is not empty. This situation is
perfectly valid and must be handled. The Gizmoproject's jabber client
put that problem in evidence.

Also added a few comments in the code as well as a handle for the
capabilities from Gmail's jabber client, which are stored in a caps:c tag
rather than the usual c tag.

Closes issue #10184.

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@79666 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent a3a32e66
No related branches found
No related tags found
No related merge requests found
...@@ -1286,29 +1286,42 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak) ...@@ -1286,29 +1286,42 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak)
found = NULL; found = NULL;
break; break;
} }
/* resource list is sorted by descending priority */
if (tmp->priority != priority) { if (tmp->priority != priority) {
found->priority = priority; found->priority = priority;
if (!last && !found->next) if (!last && !found->next)
/* resource was found to be unique,
leave loop */
break; break;
/* search for resource in our list
and take it out for the moment */
if (last) if (last)
last->next = found->next; last->next = found->next;
else else
buddy->resources = found->next; buddy->resources = found->next;
last = NULL; last = NULL;
tmp = buddy->resources; tmp = buddy->resources;
if (!buddy->resources) if (!buddy->resources)
buddy->resources = found; buddy->resources = found;
/* priority processing */
while (tmp) { while (tmp) {
/* insert resource back according to
its priority value */
if (found->priority > tmp->priority) { if (found->priority > tmp->priority) {
if (last) if (last)
/* insert within list */
last->next = found; last->next = found;
found->next = tmp; found->next = tmp;
if (!last) if (!last)
/* insert on top */
buddy->resources = found; buddy->resources = found;
break; break;
} }
if (!tmp->next) { if (!tmp->next) {
/* insert at the end of the list */
tmp->next = found; tmp->next = found;
found->next = NULL;
break; break;
} }
last = tmp; last = tmp;
...@@ -1321,6 +1334,7 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak) ...@@ -1321,6 +1334,7 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak)
tmp = tmp->next; tmp = tmp->next;
} }
/* resource not found in our list, create it */
if (!found && status != 6) { if (!found && status != 6) {
found = ast_calloc(1, sizeof(*found)); found = ast_calloc(1, sizeof(*found));
...@@ -1354,12 +1368,25 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak) ...@@ -1354,12 +1368,25 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak)
if (!tmp) if (!tmp)
buddy->resources = found; buddy->resources = found;
} }
/* if 'from' attribute does not contain 'resource' string
point to the top of our resource list */
if (!found && !pak->from->resource && buddy->resources) {
found = buddy->resources;
}
ASTOBJ_UNLOCK(buddy); ASTOBJ_UNLOCK(buddy);
ASTOBJ_UNREF(buddy, aji_buddy_destroy); ASTOBJ_UNREF(buddy, aji_buddy_destroy);
node = iks_find_attrib(iks_find(pak->x, "c"), "node"); node = iks_find_attrib(iks_find(pak->x, "c"), "node");
ver = iks_find_attrib(iks_find(pak->x, "c"), "ver"); ver = iks_find_attrib(iks_find(pak->x, "c"), "ver");
/* handle gmail client's special caps:c tag */
if (!node && !ver) {
node = iks_find_attrib(iks_find(pak->x, "caps:c"), "node");
ver = iks_find_attrib(iks_find(pak->x, "caps:c"), "ver");
}
if(status !=6 && !found->cap) { if(status !=6 && !found->cap) {
found->cap = aji_find_version(node, ver, pak); found->cap = aji_find_version(node, ver, pak);
if(gtalk_yuck(pak->x)) /* gtalk should do discover */ if(gtalk_yuck(pak->x)) /* gtalk should do discover */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment