Mercurial > pidgin.yaz
changeset 28513:7f447db0e03b
jabber: Stricter parsing of a BoB data stanza
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 31 Aug 2009 20:06:36 +0000 |
parents | 10c28fac798d |
children | 02c62c9ad822 |
files | libpurple/protocols/jabber/data.c |
diffstat | 1 files changed, 31 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/data.c Mon Aug 31 08:00:06 2009 +0000 +++ b/libpurple/protocols/jabber/data.c Mon Aug 31 20:06:36 2009 +0000 @@ -56,31 +56,42 @@ JabberData * jabber_data_create_from_xml(xmlnode *tag) { - JabberData *data = g_new0(JabberData, 1); - gsize size; - gpointer raw_data = NULL; + JabberData *data; + gchar *raw_data = NULL; + const gchar *cid, *type; + + /* check if this is a "data" tag */ + if (strcmp(tag->name, "data") != 0) { + purple_debug_error("jabber", "Invalid data element\n"); + return NULL; + } + + cid = xmlnode_get_attrib(tag, "cid"); + type = xmlnode_get_attrib(tag, "type"); - if (data == NULL) { - purple_debug_error("jabber", "Could not allocate data object\n"); + if (!cid || !type) { + purple_debug_error("jabber", "cid or type missing\n"); + return NULL; + } + + raw_data = xmlnode_get_data(tag); + if (raw_data == NULL || *raw_data == '\0') { + g_free(raw_data); + return NULL; + } + + data = g_new0(JabberData, 1); + data->data = purple_base64_decode(raw_data, &data->size); + g_free(raw_data); + + if (data->data == NULL) { + purple_debug_error("jabber", "Malformed base64 data\n"); g_free(data); return NULL; } - /* check if this is a "data" tag */ - if (strcmp(tag->name, "data") != 0) { - purple_debug_error("jabber", "Invalid data element"); - g_free(data); - return NULL; - } - - data->cid = g_strdup(xmlnode_get_attrib(tag, "cid")); - data->type = g_strdup(xmlnode_get_attrib(tag, "type")); - - raw_data = xmlnode_get_data(tag); - data->data = purple_base64_decode(raw_data, &size); - data->size = size; - - g_free(raw_data); + data->cid = g_strdup(cid); + data->type = g_strdup(type); return data; }