diff options
| author | 2015-07-18 21:50:47 +0000 | |
|---|---|---|
| committer | 2015-07-18 21:50:47 +0000 | |
| commit | a9fc612dc342f5dcd9a5bd9d0b32bda3155282ef (patch) | |
| tree | 5fc256b4b3f919b9d2de113f9785299e6340bdd4 /usr.sbin/ntpd/constraint.c | |
| parent | Make all commands accepting the "-priority" switch recognize aliases (diff) | |
| download | wireguard-openbsd-a9fc612dc342f5dcd9a5bd9d0b32bda3155282ef.tar.xz wireguard-openbsd-a9fc612dc342f5dcd9a5bd9d0b32bda3155282ef.zip | |
Handle short writes and TLS_{READ,WRITE}_AGAIN around tls_write().
input doug@; OK beck@
Diffstat (limited to 'usr.sbin/ntpd/constraint.c')
| -rw-r--r-- | usr.sbin/ntpd/constraint.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/usr.sbin/ntpd/constraint.c b/usr.sbin/ntpd/constraint.c index e688b9f7df8..cb20d621a0a 100644 --- a/usr.sbin/ntpd/constraint.c +++ b/usr.sbin/ntpd/constraint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: constraint.c,v 1.13 2015/07/18 20:32:38 bcook Exp $ */ +/* $OpenBSD: constraint.c,v 1.14 2015/07/18 21:50:47 bluhm Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -641,8 +641,9 @@ httpsdate_free(void *arg) int httpsdate_request(struct httpsdate *httpsdate, struct timeval *when) { - size_t outlen = 0, maxlength = CONSTRAINT_MAXHEADERLENGTH; - char *line, *p; + size_t outlen = 0, maxlength = CONSTRAINT_MAXHEADERLENGTH, len; + char *line, *p, *buf; + int ret; if ((httpsdate->tls_ctx = tls_client()) == NULL) goto fail; @@ -657,10 +658,17 @@ httpsdate_request(struct httpsdate *httpsdate, struct timeval *when) goto fail; } - if (tls_write(httpsdate->tls_ctx, - httpsdate->tls_request, strlen(httpsdate->tls_request), - &outlen) == -1) - goto fail; + buf = httpsdate->tls_request; + len = strlen(httpsdate->tls_request); + while (len > 0) { + ret = tls_write(httpsdate->tls_ctx, buf, len, &outlen); + if (ret == TLS_READ_AGAIN || ret == TLS_WRITE_AGAIN) + continue; + if (ret < 0) + goto fail; + buf += outlen; + len -= outlen; + } while ((line = tls_readline(httpsdate->tls_ctx, &outlen, &maxlength, when)) != NULL) { |
