pidgin: ba66150a: Use a GString here when constructing the...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Dec 15 22:50:24 EST 2008


-----------------------------------------------------------------
Revision: ba66150a2a1efc5a5cee7204adab69208825630e
Ancestor: 9a5e549612efd8ca6f60fc57b51a4eee7e32c861
Author: markdoliner at pidgin.im
Date: 2008-12-16T03:49:05
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ba66150a2a1efc5a5cee7204adab69208825630e

Modified files:
        libpurple/protocols/myspace/myspace.c

ChangeLog: 

Use a GString here when constructing the data.  It's way more
convenient.

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/myspace.c	33267a1c02c8d09f72652f34621a63cf700d03d1
+++ libpurple/protocols/myspace/myspace.c	adef48fcbba75134b17851f982a291f9b42a604e
@@ -542,9 +542,9 @@ msim_compute_login_response(const gchar 
 	guchar hash_pw[HASH_SIZE];
 	guchar key[HASH_SIZE];
 	gchar *password_utf16le, *password_utf8_lc;
-	guchar *data;
+	GString *data;
 	guchar *data_out;
-	size_t data_len, data_out_len;
+	size_t data_out_len;
 	gsize conv_bytes_read, conv_bytes_written;
 	GError *conv_error;
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
@@ -618,25 +618,25 @@ msim_compute_login_response(const gchar 
 	/* rc4 encrypt:
 	 * nonce1+email+IP list */
 
-	data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN;
-	data = g_new0(guchar, data_len);
-	memcpy(data, nonce, NONCE_SIZE);
-	memcpy(data + NONCE_SIZE, email, strlen(email));
-	memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
+	data = g_string_new(NULL);
+	g_string_append_len(data, nonce, NONCE_SIZE);
+	g_string_append(data, email);
+	g_string_append_len(data, MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
 
-	data_out = g_new0(guchar, data_len);
+	data_out = g_new0(guchar, data->len);
 
-	purple_cipher_context_encrypt(rc4, (const guchar *)data,
-			data_len, data_out, &data_out_len);
+	purple_cipher_context_encrypt(rc4, (const guchar *)data->str,
+			data->len, data_out, &data_out_len);
 	purple_cipher_context_destroy(rc4);
-	g_free(data);
 
-	if (data_out_len != data_len) {
+	if (data_out_len != data->len) {
 		purple_debug_info("msim", "msim_compute_login_response: "
 				"data length mismatch: %" G_GSIZE_FORMAT " != %"
-				G_GSIZE_FORMAT "\n", data_out_len, data_len);
+				G_GSIZE_FORMAT "\n", data_out_len, data->len);
 	}
 
+	g_string_free(data, TRUE);
+
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
 	purple_debug_info("msim", "response=<%s>\n", data_out);
 #endif


More information about the Commits mailing list