libpurple/protocols/mxit/http.c

changeset 33760
66611fba7197
parent 32157
39ba2e2492ee
parent 33744
879db2a9a59c
child 33817
5c8caea5bd66
--- a/libpurple/protocols/mxit/http.c	Mon Feb 18 15:53:46 2013 -0800
+++ b/libpurple/protocols/mxit/http.c	Mon Feb 18 17:25:08 2013 -0800
@@ -116,11 +116,12 @@
 		buflen = session->rx_i;
 
 		/* read bytes from the socket */
-		len = read( session->fd, buf + buflen, sizeof( buf ) - buflen );
+		len = read( session->fd, buf + buflen, sizeof( buf ) - ( buflen + 1 ) );
 		if ( len <= 0 ) {
 			/* connection has been terminated, or error occurred */
 			goto done;
 		}
+		buf[buflen+len] = '\0';
 
 //nextpacket:
 
@@ -181,7 +182,11 @@
 		g_free( tmp );
 		tmp = NULL;
 
-		if ( buflen > ( ( body - buf ) + bodylen ) ) {
+		if ( buflen + bodylen >= CP_MAX_PACKET ) {
+			/* this packet is way to big */
+			goto done;
+		}
+		else if ( buflen > ( ( body - buf ) + bodylen ) ) {
 			/* we have a second packet here */
 			next = body + bodylen;
 			session->rx_res = 0;

mercurial