From b9ec8de1e6bf049a024d23a5c2431f78769ba4e6 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Sat, 28 Jan 2012 12:55:34 +0000 Subject: [PATCH] disco: don't crash on replies whose is missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a regression from the BYE-BYE-LOUDMOUTH branch. The logic in request_reply_cb is meant to be: • if the stanza is an error, pass (with 'err' having been filled in); • else, if there is no node in the reply, set 'err' to that effect; • now call the callback; it is guaranteed that if err is NULL, query_node is not NULL. I inverted the check for the return value of wocky_stanza_extract_errors(): it returns TRUE if 'reply_msg' was an error, not FALSE. --- src/disco.c | 2 +- tests/twisted/Makefile.am | 1 + tests/twisted/caps/broken-reply.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletions(-) create mode 100644 tests/twisted/caps/broken-reply.py diff --git a/src/disco.c b/src/disco.c index bfe0196..d7cc236 100644 --- a/src/disco.c +++ b/src/disco.c @@ -401,7 +401,7 @@ request_reply_cb (GabbleConnection *conn, LmMessage *sent_msg, wocky_stanza_get_top_node (reply_msg), "query", disco_type_to_xmlns (request->type)); - if (!wocky_stanza_extract_errors (reply_msg, NULL, &err, NULL, NULL)) + if (wocky_stanza_extract_errors (reply_msg, NULL, &err, NULL, NULL)) { /* pass */ } diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index bf36b42..7c756ff 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -3,6 +3,7 @@ TWISTED_TESTS = \ avatar-requirements.py \ caps/advertise-contact-caps.py \ caps/advertise-legacy.py \ + caps/broken-reply.py \ caps/caps-cache.py \ caps/caps-persistent-cache.py \ caps/compat-bundles.py \ diff --git a/tests/twisted/caps/broken-reply.py b/tests/twisted/caps/broken-reply.py new file mode 100644 index 0000000..4cb63ee --- /dev/null +++ b/tests/twisted/caps/broken-reply.py @@ -0,0 +1,20 @@ +""" +Tests that disco replies whose node is missing don't crash Gabble. +""" + +from gabbletest import exec_test, sync_stream, make_result_iq +import caps_helper + +def test(q, bus, conn, stream): + jid = 'crashy@cra.shy/hi' + caps = { 'node': 'oh:hi', + 'ver': "dere", + } + h = caps_helper.send_presence(q, conn, stream, jid, caps, initial=False) + request = caps_helper.expect_disco(q, jid, caps['node'], caps) + result = make_result_iq(stream, request, add_query_node=False) + stream.send(result) + sync_stream(q, stream) + +if __name__ == '__main__': + exec_test(test) -- 1.7.7.3