From 459b58ff8218ff93f075c8c60bd8dd56b4e6fac1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 22 Aug 2020 13:03:30 -0500 Subject: Fix some ggp_xml stuff Fix const-ness of ggp_xml functions. Fix some leaks in GG XML string usage. Testing Done: Compile only. Reviewed at https://reviews.imfreedom.org/r/84/ --- libpurple/protocols/gg/oauth/oauth-purple.c | 4 +++- libpurple/protocols/gg/pubdir-prpl.c | 3 ++- libpurple/protocols/gg/roster.c | 7 +++++-- libpurple/protocols/gg/xml.c | 18 ++++++++++++------ libpurple/protocols/gg/xml.h | 12 ++++++------ 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/libpurple/protocols/gg/oauth/oauth-purple.c b/libpurple/protocols/gg/oauth/oauth-purple.c index b08603545c..b6118212c7 100644 --- a/libpurple/protocols/gg/oauth/oauth-purple.c +++ b/libpurple/protocols/gg/oauth/oauth-purple.c @@ -63,7 +63,7 @@ ggp_oauth_access_token_got(G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, gpointer user_data) { ggp_oauth_data *data = user_data; - gchar *token, *token_secret; + gchar *token = NULL, *token_secret = NULL; PurpleXmlNode *xml; gboolean succ = TRUE; @@ -81,6 +81,8 @@ ggp_oauth_access_token_got(G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, if (!succ || strlen(token) < 10) { purple_debug_error("gg", "ggp_oauth_access_token_got: invalid xml - " "token is not present"); + g_free(token); + g_free(token_secret); ggp_oauth_data_free(data); return; } diff --git a/libpurple/protocols/gg/pubdir-prpl.c b/libpurple/protocols/gg/pubdir-prpl.c index f7d96cb0be..b57ea1b602 100644 --- a/libpurple/protocols/gg/pubdir-prpl.c +++ b/libpurple/protocols/gg/pubdir-prpl.c @@ -261,7 +261,8 @@ ggp_pubdir_got_data(G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, record->age, g_date_time_to_unix(record->birth)); } - g_free(city); + g_clear_pointer(&city, g_free); + g_clear_pointer(&birth_s, g_free); xml = purple_xmlnode_get_next_twin(xml); } diff --git a/libpurple/protocols/gg/roster.c b/libpurple/protocols/gg/roster.c index 26c47d3ad6..1637b8b430 100644 --- a/libpurple/protocols/gg/roster.c +++ b/libpurple/protocols/gg/roster.c @@ -798,7 +798,8 @@ static gboolean ggp_roster_send_update_contact_update(PurpleConnection *gc, PurpleBuddy *buddy; PurpleXmlNode *buddy_node, *contact_groups; gboolean succ = TRUE; - const char *group_id; + const gchar *group_id; + gchar *guid; g_return_val_if_fail(change->type == GGP_ROSTER_CHANGE_CONTACT_UPDATE, FALSE); @@ -830,10 +831,11 @@ static gboolean ggp_roster_send_update_contact_update(PurpleConnection *gc, } /* add new */ + guid = g_uuid_string_random(); purple_debug_misc("gg", "ggp_roster_send_update_contact_update: " "adding %u...\n", uin); buddy_node = purple_xmlnode_new_child(content->contacts_node, "Contact"); - succ &= ggp_xml_set_string(buddy_node, "Guid", g_uuid_string_random()); + succ &= ggp_xml_set_string(buddy_node, "Guid", guid); succ &= ggp_xml_set_uint(buddy_node, "GGNumber", uin); succ &= ggp_xml_set_string(buddy_node, "ShowName", purple_buddy_get_alias(buddy)); @@ -850,6 +852,7 @@ static gboolean ggp_roster_send_update_contact_update(PurpleConnection *gc, /* we don't use Guid, so update is not needed * content->needs_update = TRUE; */ + g_free(guid); g_hash_table_insert(content->contact_nodes, GINT_TO_POINTER(uin), buddy_node); diff --git a/libpurple/protocols/gg/xml.c b/libpurple/protocols/gg/xml.c index c311eb61aa..f2828ca4d9 100644 --- a/libpurple/protocols/gg/xml.c +++ b/libpurple/protocols/gg/xml.c @@ -29,7 +29,8 @@ #include "xml.h" -gboolean ggp_xml_get_string(const PurpleXmlNode *xml, gchar *childName, gchar **var) +gboolean +ggp_xml_get_string(const PurpleXmlNode *xml, const gchar *childName, gchar **var) { char *str; @@ -50,7 +51,8 @@ gboolean ggp_xml_get_string(const PurpleXmlNode *xml, gchar *childName, gchar ** return TRUE; } -gboolean ggp_xml_get_bool(const PurpleXmlNode *xml, gchar *childName, gboolean *var) +gboolean +ggp_xml_get_bool(const PurpleXmlNode *xml, const gchar *childName, gboolean *var) { char *str; gboolean succ; @@ -68,7 +70,8 @@ gboolean ggp_xml_get_bool(const PurpleXmlNode *xml, gchar *childName, gboolean * return TRUE; } -gboolean ggp_xml_get_uint(const PurpleXmlNode *xml, gchar *childName, unsigned int *var) +gboolean +ggp_xml_get_uint(const PurpleXmlNode *xml, const gchar *childName, unsigned int *var) { char *str, *endptr; gboolean succ; @@ -89,7 +92,8 @@ gboolean ggp_xml_get_uint(const PurpleXmlNode *xml, gchar *childName, unsigned i return succ; } -gboolean ggp_xml_set_string(PurpleXmlNode *xml, gchar *childName, const gchar *val) +gboolean +ggp_xml_set_string(PurpleXmlNode *xml, const gchar *childName, const gchar *val) { g_return_val_if_fail(xml != NULL, FALSE); g_return_val_if_fail(val != NULL, FALSE); @@ -107,12 +111,14 @@ gboolean ggp_xml_set_string(PurpleXmlNode *xml, gchar *childName, const gchar *v return TRUE; } -gboolean ggp_xml_set_bool(PurpleXmlNode *xml, gchar *childName, gboolean val) +gboolean +ggp_xml_set_bool(PurpleXmlNode *xml, const gchar *childName, gboolean val) { return ggp_xml_set_string(xml, childName, val ? "true" : "false"); } -gboolean ggp_xml_set_uint(PurpleXmlNode *xml, gchar *childName, unsigned int val) +gboolean +ggp_xml_set_uint(PurpleXmlNode *xml, const gchar *childName, unsigned int val) { gchar buff[20]; g_snprintf(buff, sizeof(buff), "%u", val); diff --git a/libpurple/protocols/gg/xml.h b/libpurple/protocols/gg/xml.h index 7316a77f9e..08b19f021a 100644 --- a/libpurple/protocols/gg/xml.h +++ b/libpurple/protocols/gg/xml.h @@ -32,13 +32,13 @@ #include -gboolean ggp_xml_get_string(const PurpleXmlNode *xml, gchar *childName, gchar **var); -gboolean ggp_xml_get_bool(const PurpleXmlNode *xml, gchar *childName, gboolean *var); -gboolean ggp_xml_get_uint(const PurpleXmlNode *xml, gchar *childName, unsigned int *var); +gboolean ggp_xml_get_string(const PurpleXmlNode *xml, const gchar *childName, gchar **var); +gboolean ggp_xml_get_bool(const PurpleXmlNode *xml, const gchar *childName, gboolean *var); +gboolean ggp_xml_get_uint(const PurpleXmlNode *xml, const gchar *childName, unsigned int *var); -gboolean ggp_xml_set_string(PurpleXmlNode *xml, gchar *childName, const gchar *val); -gboolean ggp_xml_set_bool(PurpleXmlNode *xml, gchar *childName, gboolean val); -gboolean ggp_xml_set_uint(PurpleXmlNode *xml, gchar *childName, unsigned int val); +gboolean ggp_xml_set_string(PurpleXmlNode *xml, const gchar *childName, const gchar *val); +gboolean ggp_xml_set_bool(PurpleXmlNode *xml, const gchar *childName, gboolean val); +gboolean ggp_xml_set_uint(PurpleXmlNode *xml, const gchar *childName, unsigned int val); void ggp_xmlnode_remove_children(PurpleXmlNode *xml); -- cgit v1.2.1