/pidgin/main: 60f95045db42: Fix for TALOS-CAN-0136 part 1

Andrew Victor andrew.victor at mxit.com
Mon Jun 20 20:09:58 EDT 2016


Changeset: 60f95045db42687aca293429a4bbafe2ef537270
Author:	 Andrew Victor <andrew.victor at mxit.com>
Date:	 2016-06-03 12:57 -0500
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/60f95045db42

Description:

Fix for TALOS-CAN-0136 part 1

diffstat:

 libpurple/protocols/mxit/http.c     |  17 ++++++++++-------
 libpurple/protocols/mxit/http.h     |   4 ++--
 libpurple/protocols/mxit/protocol.c |  19 +++++++++----------
 3 files changed, 21 insertions(+), 19 deletions(-)

diffs (114 lines):

diff --git a/libpurple/protocols/mxit/http.c b/libpurple/protocols/mxit/http.c
--- a/libpurple/protocols/mxit/http.c
+++ b/libpurple/protocols/mxit/http.c
@@ -63,9 +63,9 @@ static void free_http_request( struct ht
  *  @param pktlen		The length of the packet data
  *  @return				Return -1 on error, otherwise 0
  */
-static int mxit_http_raw_write( int fd, const char* pktdata, int pktlen )
+static int mxit_http_raw_write( int fd, const char* pktdata, size_t pktlen )
 {
-	int		written;
+	size_t	written;
 	int		res;
 
 	written = 0;
@@ -315,22 +315,25 @@ static void mxit_cb_http_connect( gpoint
  *	@param session		The MXit session object
  *	@param host			The server name to connect to
  *	@param port			The port number to connect to
- *	@param data			The HTTP request data (including HTTP headers etc.)
+ *	@param header		The HTTP header.
+ *	@param data			The HTTP request data.
  *	@param datalen		The HTTP request data length
  */
-void mxit_http_send_request( struct MXitSession* session, char* host, int port, const char* data, int datalen )
+void mxit_http_send_request( struct MXitSession* session, char* host, int port, gchar* header, const char* data, size_t datalen )
 {
 	PurpleProxyConnectData*		con	= NULL;
 	struct http_request*		req;
+	size_t						headerlen = strlen( header );
 
 	/* build the http request */
 	req = g_new0( struct http_request, 1 );
 	req->session = session;
 	req->host = host;
 	req->port = port;
-	req->data = g_malloc0( datalen );
-	memcpy( req->data, data, datalen );
-	req->datalen = datalen;
+	req->data = g_malloc0( headerlen + datalen );
+	memcpy( req->data, header, headerlen );
+	memcpy( req->data + headerlen, data, datalen );
+	req->datalen = headerlen + datalen;
 
 	/* open connection to the HTTP server */
 	con = purple_proxy_connect( NULL, session->acc, host, port, mxit_cb_http_connect, req );
diff --git a/libpurple/protocols/mxit/http.h b/libpurple/protocols/mxit/http.h
--- a/libpurple/protocols/mxit/http.h
+++ b/libpurple/protocols/mxit/http.h
@@ -35,11 +35,11 @@ struct http_request
 	char*					host;
 	int						port;
 	char*					data;
-	int						datalen;
+	size_t					datalen;
 };
 
 
-void mxit_http_send_request( struct MXitSession* session, char* host, int port, const char* data, int datalen );
+void mxit_http_send_request( struct MXitSession* session, char* host, int port, gchar* header, const char* data, size_t datalen );
 
 
 
diff --git a/libpurple/protocols/mxit/protocol.c b/libpurple/protocols/mxit/protocol.c
--- a/libpurple/protocols/mxit/protocol.c
+++ b/libpurple/protocols/mxit/protocol.c
@@ -334,11 +334,10 @@ static void mxit_write_http_get( struct 
  */
 static void mxit_write_http_post( struct MXitSession* session, struct tx_packet* packet )
 {
-	char		request[256 + packet->datalen];
-	int			reqlen;
 	char*		host_name;
 	int			host_port;
 	gboolean	ok;
+	gchar*		httpheader;
 
 	/* extract the HTTP host name and host port number to connect to */
 	ok = purple_url_parse( session->http_server, &host_name, &host_port, NULL, NULL, NULL );
@@ -350,8 +349,8 @@ static void mxit_write_http_post( struct
 	packet->header[packet->headerlen - 1] = '\0';
 	packet->headerlen--;
 
-	/* build the HTTP request packet */
-	reqlen = g_snprintf( request, 256,
+	/* build the HTTP request header */
+	httpheader = g_strdup_printf(
 					"POST %s?%s HTTP/1.1\r\n"
 					"User-Agent: " MXIT_HTTP_USERAGENT "\r\n"
 					"Content-Type: application/octet-stream\r\n"
@@ -364,17 +363,17 @@ static void mxit_write_http_post( struct
 					packet->datalen - MXIT_MS_OFFSET
 	);
 
-	/* copy over the packet body data (could be binary) */
-	memcpy( request + reqlen, packet->data + MXIT_MS_OFFSET, packet->datalen - MXIT_MS_OFFSET );
-	reqlen += packet->datalen;
-
 #ifdef	DEBUG_PROTOCOL
 	purple_debug_info( MXIT_PLUGIN_ID, "HTTP POST:\n" );
-	dump_bytes( session, request, reqlen );
+	dump_bytes( session, httpheader, strlen( httpheader ) );
+	dump_bytes( session, packet->data + MXIT_MS_OFFSET, packet->datalen - MXIT_MS_OFFSET );
 #endif
 
 	/* send the request to the HTTP server */
-	mxit_http_send_request( session, host_name, host_port, request, reqlen );
+	mxit_http_send_request( session, host_name, host_port, httpheader, packet->data + MXIT_MS_OFFSET, packet->datalen - MXIT_MS_OFFSET );
+
+	/* cleanup */
+	g_free( httpheader );
 }
 
 



More information about the Commits mailing list