changeset 5310:f4912a833ff6

[gaim-migrate @ 5682] Fixed the bug where typing notifications (actually, any message where an attribute was removed) would strlen() the value just freed. This was causing the message size to be wrong on occasion (and probably very wrong on other platforms), which MSN would then puke about and cause a disconnect from the Switchboard server. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 06 May 2003 04:27:38 +0000
parents e2e53316a21d
children 3f625896f932
files src/protocols/msn/msg.c
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msg.c	Tue May 06 02:06:56 2003 +0000
+++ b/src/protocols/msn/msg.c	Tue May 06 04:27:38 2003 +0000
@@ -90,7 +90,7 @@
 
 	if (msg->size != strlen(strchr(str, '\n') + 1)) {
 		gaim_debug(GAIM_DEBUG_ERROR, "msn",
-				   "Message size (%d) and string length (%d) "
+				   "Incoming message size (%d) and string length (%d) "
 				   "do not match!\n", msg->size, strlen(str));
 	}
 
@@ -110,8 +110,6 @@
 	if (msg->incoming) {
 		msg->sender = msn_users_find_with_passport(session->users, field1);
 
-		gaim_debug(GAIM_DEBUG_MISC, "msn", "incoming message: %s, %s\n",
-				   field1, field2);
 		if (msg->sender == NULL)
 			msg->sender = msn_user_new(session, field1, field2);
 		else
@@ -196,6 +194,7 @@
 msn_message_build_string(const MsnMessage *msg)
 {
 	GList *l;
+	char *msg_start;
 	char *str;
 	char buf[MSN_BUF_LEN];
 	int len;
@@ -230,6 +229,8 @@
 
 	g_strlcpy(str, buf, len);
 
+	msg_start = str + strlen(str);
+
 	/* Standard header. */
 	if (msg->charset == NULL) {
 		g_snprintf(buf, sizeof(buf),
@@ -261,6 +262,12 @@
 
 	g_strlcat(str, buf, len);
 
+	if (msg->size != strlen(msg_start)) {
+		gaim_debug(GAIM_DEBUG_ERROR, "msn",
+				   "Outgoing message size (%d) and string length (%d) "
+				   "do not match!\n", msg->size, strlen(msg_start));
+	}
+
 	return str;
 }
 
@@ -442,6 +449,8 @@
 		if (temp != NULL) {
 			GList *l;
 
+			msg->size -= strlen(temp) + strlen(attr) + 4;
+
 			for (l = msg->attr_list; l != NULL; l = l->next) {
 				if (!g_ascii_strcasecmp(l->data, attr)) {
 					msg->attr_list = g_list_remove(msg->attr_list, l->data);
@@ -451,8 +460,6 @@
 			}
 
 			g_hash_table_remove(msg->attr_table, attr);
-
-			msg->size -= strlen(temp) + strlen(attr) + 4;
 		}
 
 		return;