summaryrefslogtreecommitdiffstats
path: root/lib/libssl/src
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2007-08-06 13:32:49 +0000
committerclaudio <claudio@openbsd.org>2007-08-06 13:32:49 +0000
commit4ca67d95c0c8df15ebbdd8d5cf55a3682324b9b4 (patch)
treea0efffd1eba8a4863b9d13b78280974f2871b1b0 /lib/libssl/src
parentFix two issues in the RIB calculation. First rt_nexthop_add() should not (diff)
downloadwireguard-openbsd-4ca67d95c0c8df15ebbdd8d5cf55a3682324b9b4.tar.xz
wireguard-openbsd-4ca67d95c0c8df15ebbdd8d5cf55a3682324b9b4.zip
Correctly NUL terminate the message buffer that is used with the
-starttls option. Without this openssl s_client -starttls crashed with malloc.conf -> J. OK deraadt@, hshoexer@
Diffstat (limited to 'lib/libssl/src')
-rw-r--r--lib/libssl/src/apps/s_client.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/libssl/src/apps/s_client.c b/lib/libssl/src/apps/s_client.c
index a70735b9dca..78bc10d3153 100644
--- a/lib/libssl/src/apps/s_client.c
+++ b/lib/libssl/src/apps/s_client.c
@@ -243,6 +243,7 @@ int MAIN(int argc, char **argv)
char *cbuf=NULL,*sbuf=NULL,*mbuf=NULL;
int cbuf_len,cbuf_off;
int sbuf_len,sbuf_off;
+ int mbuf_len,mbuf_off;
fd_set readfds,writefds;
char *port=PORT_STR;
int full_log=1;
@@ -291,7 +292,7 @@ int MAIN(int argc, char **argv)
if ( ((cbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||
((sbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||
- ((mbuf=OPENSSL_malloc(BUFSIZZ)) == NULL))
+ ((mbuf=OPENSSL_malloc(BUFSIZZ + 1)) == NULL)) /* NUL byte */
{
BIO_printf(bio_err,"out of memory\n");
goto end;
@@ -596,23 +597,42 @@ re_start:
cbuf_off=0;
sbuf_len=0;
sbuf_off=0;
+ mbuf_len=0;
+ mbuf_off=0;
/* This is an ugly hack that does a lot of assumptions */
if (starttls_proto == 1)
{
- BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_off = mbuf_len = BIO_read(sbio,mbuf,BUFSIZZ);
+ if (mbuf_len == -1)
+ {
+ BIO_printf(bio_err,"BIO_read failed\n");
+ goto end;
+ }
BIO_printf(sbio,"EHLO some.host.name\r\n");
- BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_len = BIO_read(sbio,mbuf + mbuf_off,BUFSIZZ - mbuf_off);
+ if (mbuf_len == -1)
+ {
+ BIO_printf(bio_err,"BIO_read failed\n");
+ goto end;
+ }
BIO_printf(sbio,"STARTTLS\r\n");
BIO_read(sbio,sbuf,BUFSIZZ);
}
if (starttls_proto == 2)
{
- BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_len = BIO_read(sbio,mbuf,BUFSIZZ);
+ if (mbuf_len == -1)
+ {
+ BIO_printf(bio_err,"BIO_read failed\n");
+ goto end;
+ }
BIO_printf(sbio,"STLS\r\n");
BIO_read(sbio,sbuf,BUFSIZZ);
}
+ mbuf[mbuf_off + mbuf_len] = '\0';
+
for (;;)
{
FD_ZERO(&readfds);