From c1156af9b7a5e0f1eab1cd49b29446913cc33a19 Mon Sep 17 00:00:00 2001 From: Alexander Bluhm Date: Sat, 18 Jul 2015 21:50:48 +0000 Subject: Handle short writes and TLS_{READ,WRITE}_AGAIN around tls_write(). input doug@; OK beck@ --- usr.bin/ftp/fetch.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'usr.bin/ftp') diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 9e2fbd27b07..ce1a88ff6fd 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.138 2015/02/27 17:38:19 jca Exp $ */ +/* $OpenBSD: fetch.c,v 1.139 2015/07/18 21:50:47 bluhm Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -1509,13 +1509,23 @@ ftp_printf(FILE *fp, struct tls *tls, const char *fmt, ...) int SSL_vprintf(struct tls *tls, const char *fmt, va_list ap) { - char *string; - size_t nw; + char *string, *buf; + size_t nw, len; int ret; if ((ret = vasprintf(&string, fmt, ap)) == -1) return ret; - ret = tls_write(tls, string, ret, &nw); + buf = string; + len = ret; + while (len > 0) { + ret = tls_write(tls, buf, len, &nw); + if (ret == TLS_READ_AGAIN || ret == TLS_WRITE_AGAIN) + continue; + if (ret < 0) + break; + buf += nw; + len -= nw; + } free(string); return ret; } -- cgit v1.2.3