changeset 15226:2af69418b24e

[gaim-migrate @ 18016] gg: Don't crash with unexpected buddy list format. (Fixes #1609482) committer: Tailor Script <tailor@pidgin.im>
author Bartoz Oler <bartosz@pidgin.im>
date Sun, 17 Dec 2006 13:07:25 +0000
parents 9a58a9ea3995
children a5ef8fc9fbeb
files libgaim/protocols/gg/buddylist.c libgaim/protocols/gg/gg-utils.c libgaim/protocols/gg/gg-utils.h
diffstat 3 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/protocols/gg/buddylist.c	Sun Dec 17 12:59:04 2006 +0000
+++ b/libgaim/protocols/gg/buddylist.c	Sun Dec 17 13:07:25 2006 +0000
@@ -90,10 +90,8 @@
 	gchar **users_tbl;
 	int i;
 
-	/*
-	 * XXX: Limit of entries in a buddylist that will be imported.
-	 */
-	users_tbl = g_strsplit(buddylist, "\r\n", 200);
+	/* Don't limit a number of records in a buddylist. */
+	users_tbl = g_strsplit(buddylist, "\r\n", -1);
 
 	for (i = 0; users_tbl[i] != NULL; i++) {
 		gchar **data_tbl;
@@ -103,17 +101,23 @@
 			continue;
 
 		data_tbl = g_strsplit(users_tbl[i], ";", 8);
+		if (ggp_array_size(data_tbl) < 8) {
+			gaim_debug_warning("gg", 
+				"Something is wrong on line %d of the buddylist. Skipping.\n",
+				i + 1);
+			continue;
+		}
 
 		show = charset_convert(data_tbl[3], "CP1250", "UTF-8");
 		name = data_tbl[6];
-		if (NULL == name || '\0' == *name) {
+		if ('\0' == *name) {
 			gaim_debug_warning("gg",
 				"Something is wrong on line %d of the buddylist. Skipping.\n",
 				i + 1);
 			continue;
 		}
 
-		if (NULL == show || '\0' == *show) {
+		if ('\0' == *show) {
 			show = g_strdup(name);
 		}
 
@@ -127,10 +131,11 @@
 
 		g = g_strdup("Gadu-Gadu");
 
-		if (strlen(data_tbl[5])) {
+		if ('\0' != data_tbl[5]) {
+			/* XXX: Probably buddy should be added to all the groups. */
 			/* Hard limit to at most 50 groups */
 			gchar **group_tbl = g_strsplit(data_tbl[5], ",", 50);
-			if (strlen(group_tbl[0]) > 0) {
+			if (ggp_array_size(group_tbl) > 0) {
 				g_free(g);
 				g = g_strdup(group_tbl[0]);
 			}
--- a/libgaim/protocols/gg/gg-utils.c	Sun Dec 17 12:59:04 2006 +0000
+++ b/libgaim/protocols/gg/gg-utils.c	Sun Dec 17 13:07:25 2006 +0000
@@ -50,6 +50,18 @@
 }
 /* }}} */
 
+/* unsigned int ggp_array_size(char **array) {{{ */
+unsigned int ggp_array_size(char **array)
+{
+	unsigned int i;
+
+	for (i = 0; array[i] != NULL && i < UINT_MAX; i++)
+	{}
+
+	return i;
+}
+/* }}} */
+
 /* char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) {{{ */
 char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst)
 {
--- a/libgaim/protocols/gg/gg-utils.h	Sun Dec 17 12:59:04 2006 +0000
+++ b/libgaim/protocols/gg/gg-utils.h	Sun Dec 17 13:07:25 2006 +0000
@@ -38,16 +38,27 @@
 #include "gg.h"
 
 
-/*
+/**
  * Convert a base 10 string to a UIN.
  *
  * @param str The string to convert
- * @return    UIN or 0 if an error occurred.
+ *
+ * @return UIN or 0 if an error occurred.
  */
 uin_t
 ggp_str_to_uin(const char *str);
 
 /**
+ * Calculate size of a NULL-terminated array.
+ *
+ * @param array The array.
+ *
+ * @return Size of the array.
+ */
+unsigned int
+ggp_array_size(char **array);
+
+/**
  * Convert enconding of a given string.
  *
  * @param locstr Input string.