pidgin: 844313d8: The TLV list should be padded to a multi...

qulogic at pidgin.im qulogic at pidgin.im
Fri May 6 02:36:38 EDT 2011


----------------------------------------------------------------------
Revision: 844313d83191cb5ce41402a24febba9e59dfd576
Parent:   1a9df376c3e5a53f210cec632c3471d97d588420
Author:   qulogic at pidgin.im
Date:     05/05/11 18:19:36
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/844313d83191cb5ce41402a24febba9e59dfd576

Changelog: 

The TLV list should be padded to a multiple of 4.

Changes against parent 1a9df376c3e5a53f210cec632c3471d97d588420

  patched  libpurple/protocols/msn/tlv.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/tlv.c	e704d17a9c254d2bf125c3b8dd7bf4d75a196ead
+++ libpurple/protocols/msn/tlv.c	d9b98b49c632f6426b0e848d1a3444d91e80a034
@@ -54,9 +54,21 @@ msn_tlvlist_read(const char *bs, size_t 
 		guint8 type, length;
 		msn_tlv_t *tlv;
 
-		if (bs_len < 2) {
-			msn_tlvlist_free(list);
-			return NULL;
+		if (bs_len == 3 && *bs == 0) {
+			/* Padding to multiple of 4 */
+			break;
+		} else if (bs_len == 2 && *bs == 0) {
+			/* Padding to multiple of 4 */
+			break;
+		} else if (bs_len == 1) {
+			if (*bs == 0) {
+				/* Padding to multiple of 4 */
+				break;
+			} else {
+				/* TLV is not small enough to fit here */
+				msn_tlvlist_free(list);
+				return NULL;
+			}
 		}
 
 		type = msn_pop8(bs);
@@ -330,8 +342,16 @@ msn_tlvlist_write(GSList *list, size_t *
 		bytes_left -= (tlv->length + 2);
 	}
 
-	*out_len = total_len - bytes_left;
+	/* Align length to multiple of 4 */
+	total_len = total_len - bytes_left;
+	bytes_left = 4 - total_len % 4;
+	if (bytes_left != 4)
+		memset(tmp, 0, bytes_left);
+	else
+		bytes_left = 0;
 
+	*out_len = total_len + bytes_left;
+
 	return buf;
 }
 


More information about the Commits mailing list