summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bytestream-factory.c27
-rw-r--r--src/conn-aliasing.c4
-rw-r--r--src/connection.c9
-rw-r--r--src/muc-channel.c2
-rw-r--r--src/tube-dbus.c7
-rw-r--r--src/util.c8
-rw-r--r--src/util.h4
-rw-r--r--tests/test-jid-decode.c8
-rw-r--r--tests/twisted/file-transfer/file_transfer_helper.py5
9 files changed, 49 insertions, 25 deletions
diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c
index 84a85a982..255535e52 100644
--- a/src/bytestream-factory.c
+++ b/src/bytestream-factory.c
@@ -967,7 +967,19 @@ bytestream_factory_iq_si_cb (LmMessageHandler *handler,
if (room_handle == 0)
{
/* jid is not a muc jid so we need contact's resource */
- gabble_decode_jid (from, NULL, NULL, &peer_resource);
+
+ if (!gabble_decode_jid (from, NULL, NULL, &peer_resource))
+ {
+ DEBUG ("Got an SI IQ response from a bad JID. Ignoring.");
+ goto out;
+ }
+
+ if (!peer_resource || peer_resource[0] == '\0')
+ {
+ DEBUG ("Got an SI IQ response from a JID without a resource."
+ "Ignoring.");
+ goto out;
+ }
peer_handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
@@ -1866,7 +1878,18 @@ streaminit_reply_cb (GabbleConnection *conn,
if (room_handle == 0)
{
/* jid is not a muc jid so we need contact's resource */
- gabble_decode_jid (from, NULL, NULL, &peer_resource);
+
+ if (!gabble_decode_jid (from, NULL, NULL, &peer_resource))
+ {
+ DEBUG ("Got an SI request with a bad JID");
+ goto END;
+ }
+
+ if (peer_resource == NULL || peer_resource[0] == '\0')
+ {
+ DEBUG ("Got an SI request from a JID without a resource; ignoring");
+ goto END;
+ }
/* we are not in a muc so our own jid is the one in the 'to' attribute */
self_jid = g_strdup (lm_message_node_get_attribute (reply_msg->node,
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 9bc331a2a..3a19fcf89 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -889,10 +889,10 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
jid = tp_handle_inspect (contact_handles, handle);
g_assert (NULL != jid);
- gabble_decode_jid (jid, NULL, NULL, &resource);
/* MUC handles have the nickname in the resource */
- if (NULL != resource)
+ if (gabble_decode_jid (jid, NULL, NULL, &resource) &&
+ NULL != resource)
{
set_or_clear (alias, resource);
return GABBLE_CONNECTION_ALIAS_FROM_MUC_RESOURCE;
diff --git a/src/connection.c b/src/connection.c
index 5ef126124..79a300a25 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -975,9 +975,8 @@ _gabble_connection_set_properties_from_account (GabbleConnection *conn,
username = server = resource = NULL;
result = TRUE;
- gabble_decode_jid (account, &username, &server, &resource);
-
- if (username == NULL || server == NULL ||
+ if (!gabble_decode_jid (account, &username, &server, &resource) ||
+ username == NULL || server == NULL ||
*username == '\0' || *server == '\0')
{
g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
@@ -3190,9 +3189,9 @@ room_jid_verify (RoomVerifyBatch *batch,
GError *error = NULL;
room = service = NULL;
- gabble_decode_jid (batch->contexts[i].jid, &room, &service, NULL);
- if (room == NULL || *room == '\0' || service == NULL || *service == '\0')
+ if (!gabble_decode_jid (batch->contexts[i].jid, &room, &service, NULL) ||
+ room == NULL || *room == '\0' || service == NULL || *service == '\0')
{
g_set_error (&error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
"unable to get room name and service from JID %s",
diff --git a/src/muc-channel.c b/src/muc-channel.c
index c5b6ab8c1..cce471b94 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -697,7 +697,7 @@ create_room_identity (GabbleMucChannel *chan)
*/
gchar *local_part;
- gabble_decode_jid (alias, &local_part, NULL, NULL);
+ g_assert (gabble_decode_jid (alias, &local_part, NULL, NULL));
g_assert (local_part != NULL);
g_free (alias);
diff --git a/src/tube-dbus.c b/src/tube-dbus.c
index 9e0cce377..646438ae6 100644
--- a/src/tube-dbus.c
+++ b/src/tube-dbus.c
@@ -919,8 +919,9 @@ gabble_tube_dbus_constructor (GType type,
priv->dbus_name_to_handle = g_hash_table_new_full (g_str_hash,
g_str_equal, NULL, NULL);
- gabble_decode_jid (tp_handle_inspect (contact_repo, priv->self_handle),
- NULL, NULL, &nick);
+ g_assert (gabble_decode_jid (
+ tp_handle_inspect (contact_repo, priv->self_handle),
+ NULL, NULL, &nick));
priv->dbus_local_name = _gabble_generate_dbus_unique_name (nick);
@@ -1679,7 +1680,7 @@ gabble_tube_dbus_add_name (GabbleTubeDBus *self,
const gchar *jid;
jid = tp_handle_inspect (contact_repo, handle);
- gabble_decode_jid (jid, NULL, NULL, &nick);
+ g_assert (gabble_decode_jid (jid, NULL, NULL, &nick));
supposed_name = _gabble_generate_dbus_unique_name (nick);
g_free (nick);
diff --git a/src/util.c b/src/util.c
index 07dfb5f02..685739ed4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -426,7 +426,7 @@ lm_message_build_with_sub_type (const gchar *to, LmMessageType type,
* domain are lower-cased because the Jabber protocol treats them
* case-insensitively.
*/
-void
+gboolean
gabble_decode_jid (const gchar *jid,
gchar **node,
gchar **domain,
@@ -489,6 +489,7 @@ gabble_decode_jid (const gchar *jid,
/* free our working copy */
g_free (tmp_jid);
+ return TRUE;
}
/**
@@ -590,9 +591,8 @@ gabble_normalize_contact (TpHandleRepoIface *repo,
gchar *username = NULL, *server = NULL, *resource = NULL;
gchar *ret = NULL;
- gabble_decode_jid (jid, &username, &server, &resource);
-
- if (!username || !server || !username[0] || !server[0])
+ if (!gabble_decode_jid (jid, &username, &server, &resource) ||
+ !username || !server || !username[0] || !server[0])
{
INVALID_HANDLE (error,
"jid %s has invalid username or server", jid);
diff --git a/src/util.h b/src/util.h
index 0bdde9bf5..1cf1ddf3e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -61,8 +61,8 @@ G_GNUC_NULL_TERMINATED LmMessage * lm_message_build_with_sub_type (
const gchar *to, LmMessageType type, LmMessageSubType sub_type,
guint spec, ...);
-/* format: a@b/c */
-void gabble_decode_jid (const gchar *jid, gchar **a, gchar **b, gchar **c);
+G_GNUC_WARN_UNUSED_RESULT
+gboolean gabble_decode_jid (const gchar *jid, gchar **a, gchar **b, gchar **c);
gchar *gabble_remove_resource (const gchar *jid);
gchar *gabble_normalize_contact (TpHandleRepoIface *repo, const gchar *jid,
diff --git a/tests/test-jid-decode.c b/tests/test-jid-decode.c
index e6032dece..bc780dde7 100644
--- a/tests/test-jid-decode.c
+++ b/tests/test-jid-decode.c
@@ -12,7 +12,7 @@ test1 (void)
gchar *server = NULL;
gchar *resource = NULL;
- gabble_decode_jid ("", &node, &server, &resource);
+ g_assert (gabble_decode_jid ("", &node, &server, &resource));
g_assert (node == NULL);
g_assert (0 == strcmp (server, ""));
g_assert (resource == NULL);
@@ -26,7 +26,7 @@ test2 (void)
gchar *server = NULL;
gchar *resource = NULL;
- gabble_decode_jid ("bar", &node, &server, &resource);
+ g_assert (gabble_decode_jid ("bar", &node, &server, &resource));
g_assert (node == NULL);
g_assert (0 == strcmp (server, "bar"));
g_assert (resource == NULL);
@@ -40,7 +40,7 @@ test3 (void)
gchar *server = NULL;
gchar *resource = NULL;
- gabble_decode_jid ("foo@bar", &node, &server, &resource);
+ g_assert (gabble_decode_jid ("foo@bar", &node, &server, &resource));
g_assert (0 == strcmp (node, "foo"));
g_assert (0 == strcmp (server, "bar"));
g_assert (resource == NULL);
@@ -55,7 +55,7 @@ test4 (void)
gchar *server = NULL;
gchar *resource = NULL;
- gabble_decode_jid ("foo@bar/baz", &node, &server, &resource);
+ g_assert (gabble_decode_jid ("foo@bar/baz", &node, &server, &resource));
g_assert (0 == strcmp (node, "foo"));
g_assert (0 == strcmp (server, "bar"));
g_assert (0 == strcmp (resource, "baz"));
diff --git a/tests/twisted/file-transfer/file_transfer_helper.py b/tests/twisted/file-transfer/file_transfer_helper.py
index 3a4f47980..49e450c8d 100644
--- a/tests/twisted/file-transfer/file_transfer_helper.py
+++ b/tests/twisted/file-transfer/file_transfer_helper.py
@@ -43,6 +43,7 @@ class File(object):
class FileTransferTest(object):
CONTACT_NAME = 'test-ft@localhost'
+ CONTACT_FULL_JID = 'test-ft@localhost/Telepathy'
def __init__(self, bytestream_cls, file, address_type, access_control, access_control_param):
self.file = file
@@ -65,7 +66,7 @@ class FileTransferTest(object):
roster = make_result_iq(self.stream, roster_event.stanza)
query = roster.firstChildElement()
item = query.addElement('item')
- item['jid'] = self.CONTACT_NAME
+ item['jid'] = self.CONTACT_FULL_JID
item['subscription'] = 'both'
self.stream.send(roster)
@@ -150,7 +151,7 @@ class ReceiveFileTest(FileTransferTest):
def send_ft_offer_iq(self):
self.bytestream = self.bytestream_cls(self.stream, self.q, 'alpha',
- self.contact_name, 'test@localhost/Resource', True)
+ self.contact_full_jid, 'test@localhost/Resource', True)
iq, si = self.bytestream.create_si_offer(ns.FILE_TRANSFER)