summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2013-05-19 01:20:56 +0200
committerBerke Viktor <bviktor@hexchat.org>2013-05-19 01:21:27 +0200
commitf778245a86dcec0879794e0f35601965da221b46 (patch)
treeefa0288d3fb3bcb2a7cd4b0ff605959f360bd0a6
parent5701ba287b94b531c854361984c1ca2eb07cad74 (diff)
Simplify SASL auth string generation code
-rw-r--r--src/common/util.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 5c09992b..71766f88 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1931,19 +1931,15 @@ get_subdirs (const char *path)
 char *
 encode_sasl_pass (char *user, char *pass)
 {
-	int passlen;
+	int authlen;
 	char *buffer;
 	char *encoded;
 
-	/* passphrase generation, nicely copy-pasted from the CAP-SASL plugin */
-	passlen = strlen (user) * 2 + 2 + strlen (pass);
-	buffer = (char*) malloc (passlen + 1);
-	strcpy (buffer, user);
-	strcpy (buffer + strlen (user) + 1, user);
-	strcpy (buffer + strlen (user) * 2 + 2, pass);
-	encoded = g_base64_encode ((unsigned char*) buffer, passlen);
-
-	free (buffer);
+	/* we can't call strlen() directly on buffer thanks to the atrocious \0 characters it requires */
+	authlen = strlen (user) * 2 + 2 + strlen (pass);
+	buffer = g_strdup_printf ("%s%c%s%c%s", user, '\0', user, '\0', pass);
+	encoded = g_base64_encode ((unsigned char*) buffer, authlen);
+	g_free (buffer);
 
 	return encoded;
 }