masqmail

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
parents e230bcd0f1c6
children fa62b148bb14
files src/base64/base64.c src/smtp_out.c
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/src/base64/base64.c	Sun Apr 24 19:37:56 2011 +0200
     1.2 +++ b/src/base64/base64.c	Sun Apr 24 20:13:47 2011 +0200
     1.3 @@ -40,7 +40,8 @@
     1.4  	enc[i++] = '+';
     1.5  	enc[i++] = '/';
     1.6  
     1.7 -	outbuf = g_malloc(((len + 3) * 8) / 6);
     1.8 +	outbuf = g_malloc(((len + 3) * 8) / 6 +1);
     1.9 +	memset(outbuf, 0, ((len + 3) * 8) / 6 +1);
    1.10  	q = outbuf;
    1.11  
    1.12  	i = 0;
    1.13 @@ -78,7 +79,8 @@
    1.14  	guchar *p = buf, *q;
    1.15  	guint in[4];
    1.16  	/* gchar *out = g_malloc(((strlen(buf)+3) * 3) / 4 + 1); */
    1.17 -	gchar *out = g_malloc((strlen(buf) + 3) + 1);
    1.18 +	gchar *out = g_malloc((strlen(buf) + 3) + 1 +1);
    1.19 +	memset(out, 0, (strlen(buf) + 3) + 1 +1);
    1.20  
    1.21  	q = out;
    1.22  	*size = 0;
    1.23 @@ -125,5 +127,6 @@
    1.24  			}
    1.25  		}
    1.26  	}
    1.27 +	out[*size] = '\0';
    1.28  	return out;
    1.29  }
     2.1 --- a/src/smtp_out.c	Sun Apr 24 19:37:56 2011 +0200
     2.2 +++ b/src/smtp_out.c	Sun Apr 24 20:13:47 2011 +0200
     2.3 @@ -628,10 +628,10 @@
     2.4  
     2.5  			DEBUG(5) debugf("smtp_out_auth_login():\n");
     2.6  			resp64 = get_response_arg(&(psb->buffer[4]));
     2.7 -			DEBUG(5) debugf("  encoded response = %s\n", resp64);
     2.8 +			DEBUG(5) debugf("  encoded response = `%s'\n", resp64);
     2.9  			resp = base64_decode(resp64, &resp_size);
    2.10  			g_free(resp64);
    2.11 -			DEBUG(5) debugf("  decoded response = %s, size = %d\n", resp, resp_size);
    2.12 +			DEBUG(5) debugf("  decoded response = `%s', size = %d\n", resp, resp_size);
    2.13  			g_free(resp);
    2.14  			reply64 = base64_encode(psb->auth_login, strlen(psb->auth_login));
    2.15  			fprintf(psb->out, "%s\r\n", reply64);
    2.16 @@ -641,10 +641,10 @@
    2.17  			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
    2.18  				if ((ok = check_response(psb, TRUE))) {
    2.19  					resp64 = get_response_arg(&(psb->buffer[4]));
    2.20 -					DEBUG(5) debugf("  encoded response = %s\n", resp64);
    2.21 +					DEBUG(5) debugf("  encoded response = `%s'\n", resp64);
    2.22  					resp = base64_decode(resp64, &resp_size);
    2.23  					g_free(resp64);
    2.24 -					DEBUG(5) debugf("  decoded response = %s, size = %d\n", resp, resp_size);
    2.25 +					DEBUG(5) debugf("  decoded response = `%s', size = %d\n", resp, resp_size);
    2.26  					g_free(resp);
    2.27  					reply64 = base64_encode(psb->auth_secret, strlen(psb->auth_secret));
    2.28  					fprintf(psb->out, "%s\r\n", reply64);