From: Kevin McCarthy Date: Mon, 11 Apr 2016 19:45:25 +0000 (-0700) Subject: Add null-terminator to BIO_get_mem_data() output. X-Git-Tag: neomutt-20160822~174 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7654dcf1bcc4a0c267d78198514169f9c7c79a5;p=neomutt Add null-terminator to BIO_get_mem_data() output. It turns out the output isn't necessarily null-terminated. --- diff --git a/mutt_ssl.c b/mutt_ssl.c index 30da838e9..78d848982 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -549,12 +549,20 @@ static void ssl_dprint_err_stack (void) #ifdef DEBUG BIO *bio; char *buf = NULL; + long buflen; + char *output; if (! (bio = BIO_new (BIO_s_mem ()))) return; ERR_print_errors (bio); - if (BIO_get_mem_data (bio, &buf)) - dprint (1, (debugfile, "SSL error stack: %s\n", buf)); + if ((buflen = BIO_get_mem_data (bio, &buf)) > 0) + { + output = safe_malloc (buflen + 1); + memcpy (output, buf, buflen); + output[buflen] = '\0'; + dprint (1, (debugfile, "SSL error stack: %s\n", output)); + FREE (&output); + } BIO_free (bio); #endif }