changeset 312:c74adb7c4f50

null-terminated the decoded base64 strings The returned size is still the same. I only alloced one byte more and filled it with zero. TODO: I'm not sure if the allocated size is exact. It's large enough but maybe too large.
author meillo@marmaro.de
date Sun, 24 Apr 2011 20:13:47 +0200 (2011-04-24)
parents e230bcd0f1c6
children fa62b148bb14
files src/base64/base64.c src/smtp_out.c
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/base64/base64.c	Sun Apr 24 19:37:56 2011 +0200
+++ b/src/base64/base64.c	Sun Apr 24 20:13:47 2011 +0200
@@ -40,7 +40,8 @@
 	enc[i++] = '+';
 	enc[i++] = '/';
 
-	outbuf = g_malloc(((len + 3) * 8) / 6);
+	outbuf = g_malloc(((len + 3) * 8) / 6 +1);
+	memset(outbuf, 0, ((len + 3) * 8) / 6 +1);
 	q = outbuf;
 
 	i = 0;
@@ -78,7 +79,8 @@
 	guchar *p = buf, *q;
 	guint in[4];
 	/* gchar *out = g_malloc(((strlen(buf)+3) * 3) / 4 + 1); */
-	gchar *out = g_malloc((strlen(buf) + 3) + 1);
+	gchar *out = g_malloc((strlen(buf) + 3) + 1 +1);
+	memset(out, 0, (strlen(buf) + 3) + 1 +1);
 
 	q = out;
 	*size = 0;
@@ -125,5 +127,6 @@
 			}
 		}
 	}
+	out[*size] = '\0';
 	return out;
 }
--- a/src/smtp_out.c	Sun Apr 24 19:37:56 2011 +0200
+++ b/src/smtp_out.c	Sun Apr 24 20:13:47 2011 +0200
@@ -628,10 +628,10 @@
 
 			DEBUG(5) debugf("smtp_out_auth_login():\n");
 			resp64 = get_response_arg(&(psb->buffer[4]));
-			DEBUG(5) debugf("  encoded response = %s\n", resp64);
+			DEBUG(5) debugf("  encoded response = `%s'\n", resp64);
 			resp = base64_decode(resp64, &resp_size);
 			g_free(resp64);
-			DEBUG(5) debugf("  decoded response = %s, size = %d\n", resp, resp_size);
+			DEBUG(5) debugf("  decoded response = `%s', size = %d\n", resp, resp_size);
 			g_free(resp);
 			reply64 = base64_encode(psb->auth_login, strlen(psb->auth_login));
 			fprintf(psb->out, "%s\r\n", reply64);
@@ -641,10 +641,10 @@
 			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
 				if ((ok = check_response(psb, TRUE))) {
 					resp64 = get_response_arg(&(psb->buffer[4]));
-					DEBUG(5) debugf("  encoded response = %s\n", resp64);
+					DEBUG(5) debugf("  encoded response = `%s'\n", resp64);
 					resp = base64_decode(resp64, &resp_size);
 					g_free(resp64);
-					DEBUG(5) debugf("  decoded response = %s, size = %d\n", resp, resp_size);
+					DEBUG(5) debugf("  decoded response = `%s', size = %d\n", resp, resp_size);
 					g_free(resp);
 					reply64 = base64_encode(psb->auth_secret, strlen(psb->auth_secret));
 					fprintf(psb->out, "%s\r\n", reply64);