pidgin: 31a6cb7c: Make the oscar cleanlist function ensure...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Dec 12 04:05:22 EST 2011


----------------------------------------------------------------------
Revision: 31a6cb7c7aaed62b686fa3d4403dbed06d291abd
Parent:   eb6023a30168a26f129e0626d18aa50710475d1b
Author:   markdoliner at pidgin.im
Date:     12/12/11 04:01:21
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/31a6cb7c7aaed62b686fa3d4403dbed06d291abd

Changelog: 

Make the oscar cleanlist function ensure that buddy comments and aliases
are valid utf8.  If they're not, then we use purple_utf8_salvage()
to fix them and save the result in our server list.

Changes against parent eb6023a30168a26f129e0626d18aa50710475d1b

  patched  libpurple/protocols/oscar/family_feedbag.c

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/family_feedbag.c	9d088e91d255b2df6c9b648de072809886b172d7
+++ libpurple/protocols/oscar/family_feedbag.c	122332a388a13ffea8eec5ff840bef74da822bab
@@ -734,10 +734,37 @@ aim_ssi_freelist(OscarData *od)
 }
 
 /**
- * This "cleans" the ssi list.  It does the following:
- * 1) Makes sure all buddies, permits, and denies have names.
- * 2) Makes sure that all buddies are in a group that exist.
- * 3) Deletes any empty groups
+ * Look up the given TLV type in the item's data.  If the value of
+ * the TLV is not a valid UTF-8 string then use purple_utf8_salvage()
+ * to replace invalid bytes with question marks.
+ */
+static void cleanlist_ensure_utf8_data(struct aim_ssi_item *item, guint16 tlvtype)
+{
+	aim_tlv_t *tlv;
+	gchar *value, *salvaged;
+
+	tlv = aim_tlv_gettlv(item->data, tlvtype, 1);
+	if (tlv && tlv->length && !g_utf8_validate((const gchar *)tlv->value, tlv->length, NULL)) {
+		purple_debug_warning("oscar", "cleanlist found invalid UTF-8 "
+				"for 0x%04hx field of 0x%04hx item with name %s.  "
+				"Attempting to repair.\n",
+				tlvtype, item->type, item->name ? item->name : "(null)");
+		value = g_strndup((const gchar *)tlv->value, tlv->length);
+		salvaged = purple_utf8_salvage(value);
+		g_free(value);
+		if (*salvaged)
+			aim_tlvlist_replace_str(&item->data, tlvtype, salvaged);
+		else
+			aim_tlvlist_remove(&item->data, tlvtype);
+		g_free(salvaged);
+	}
+}
+
+/**
+ * This "cleans" the ssi list.  It does things like:
+ * - Makes sure all buddies, permits, and denies have names
+ * - Makes sure all buddies are in a group that exist
+ * - Makes sure strings are valid UTF-8
  *
  * @param od The oscar odion.
  * @return Return 0 if no errors, otherwise return the error number.
@@ -792,6 +819,12 @@ int aim_ssi_cleanlist(OscarData *od)
 				}
 				cur2 = next2;
 			}
+
+			/* Make sure alias is valid UTF-8 */
+			cleanlist_ensure_utf8_data(cur, 0x0131);
+
+			/* Make sure comment is valid UTF-8 */
+			cleanlist_ensure_utf8_data(cur, 0x013c);
 		}
 		cur = cur->next;
 	}


More information about the Commits mailing list