From a35dadc4069721ffee181123ef379f60a9055716 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 18 Oct 2011 15:46:11 +0200 Subject: [PATCH] _tp_channel_contacts_queue_prepare_finish: don't assume item->contacts is not NULL For example, when receiving a MUC delivery report we end up with a message having no sender and so no contact to prepare. https://bugs.freedesktop.org/show_bug.cgi?id=41929 --- telepathy-glib/channel-contacts.c | 7 ++++- tests/dbus/text-channel.c | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletions(-) diff --git a/telepathy-glib/channel-contacts.c b/telepathy-glib/channel-contacts.c index f5de15b..88f968f 100644 --- a/telepathy-glib/channel-contacts.c +++ b/telepathy-glib/channel-contacts.c @@ -484,7 +484,12 @@ _tp_channel_contacts_queue_prepare_finish (TpChannel *self, item = g_simple_async_result_get_op_res_gpointer (simple); if (contacts != NULL) - *contacts = g_ptr_array_ref (item->contacts); + { + if (item->contacts != NULL) + *contacts = g_ptr_array_ref (item->contacts); + else + *contacts = g_ptr_array_new (); + } if (g_simple_async_result_propagate_error (simple, error)) return FALSE; diff --git a/tests/dbus/text-channel.c b/tests/dbus/text-channel.c index a33292d..a292640 100644 --- a/tests/dbus/text-channel.c +++ b/tests/dbus/text-channel.c @@ -923,6 +923,51 @@ test_sent_with_no_sender (Test *test, g_ptr_array_unref (parts); } +/* regression test for fdo #41929 */ +static void +test_receive_muc_delivery (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GQuark features[] = { TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, 0 }; + GPtrArray *parts; + GHashTable *header; + + /* We have to prepare the pending messages feature to be notified about + * incoming messages */ + tp_proxy_prepare_async (test->channel, features, + proxy_prepare_cb, test); + + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + g_signal_connect (test->channel, "message-received", + G_CALLBACK (message_received_cb), test); + + /* build delivery report */ + parts = g_ptr_array_new_with_free_func ((GDestroyNotify) g_hash_table_unref); + header = tp_asv_new (NULL, NULL); + g_ptr_array_add (parts, header); + + tp_asv_set_uint32 (header, "message-type", + TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT); + tp_asv_set_uint32 (header, "pending-message-id", 5); + tp_asv_set_string (header, "message-token", "message_token"); + tp_asv_set_string (header, "delivery-token", "delivery_token"); + tp_asv_set_uint32 (header, "delivery-status", TP_DELIVERY_STATUS_DELIVERED); + + tp_svc_channel_interface_messages_emit_message_received (test->chan_service, + parts); + + test->wait = 1; + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + g_assert_cmpuint (tp_message_get_message_type (test->received_msg), ==, + TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT); + + g_ptr_array_unref (parts); +} + int main (int argc, char **argv) @@ -956,6 +1001,8 @@ main (int argc, test_sender_prepared, teardown); g_test_add ("/text-channel/sent-with-no-sender", Test, NULL, setup, test_sent_with_no_sender, teardown); + g_test_add ("/text-channel/receive-muc-delivery", Test, NULL, setup, + test_receive_muc_delivery, teardown); return g_test_run (); } -- 1.7.4.1