From fb9f42e04d1f20ac7d0179d07f4ab7f559948fa6 Mon Sep 17 00:00:00 2001 From: Roelof duToit Date: Thu, 13 Jul 2017 13:07:26 -0400 Subject: [PATCH] Retry SSL_read on ERROR_WANT_READ. This resolves the retry issue in general, but also the specific case where a TLS 1.3 server sends a post-handshake NewSessionTicket message prior to appdata. Reviewed-by: Tim Hudson Reviewed-by: Bernd Edlinger Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/3925) --- apps/s_time.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/s_time.c b/apps/s_time.c index 263502c753..233b689144 100644 --- a/apps/s_time.c +++ b/apps/s_time.c @@ -229,8 +229,8 @@ int s_time_main(int argc, char **argv) fmt_http_get_cmd, www_path); if (SSL_write(scon, buf, buf_len) <= 0) goto end; - while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) - bytes_read += i; + while ((i = SSL_read(scon, buf, sizeof(buf))) > 0 || SSL_get_error(scon, i) == SSL_ERROR_WANT_READ) + if (i > 0) bytes_read += i; } #ifdef NO_SHUTDOWN SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); @@ -287,7 +287,7 @@ int s_time_main(int argc, char **argv) fmt_http_get_cmd, www_path); if (SSL_write(scon, buf, buf_len) <= 0) goto end; - while (SSL_read(scon, buf, sizeof(buf)) > 0) + while ((i = SSL_read(scon, buf, sizeof(buf))) > 0 || SSL_get_error(scon, i) == SSL_ERROR_WANT_READ) continue; } #ifdef NO_SHUTDOWN @@ -318,8 +318,8 @@ int s_time_main(int argc, char **argv) www_path); if (SSL_write(scon, buf, strlen(buf)) <= 0) goto end; - while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) - bytes_read += i; + while ((i = SSL_read(scon, buf, sizeof(buf))) > 0 || SSL_get_error(scon, i) == SSL_ERROR_WANT_READ) + if (i > 0) bytes_read += i; } #ifdef NO_SHUTDOWN SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); -- 2.25.1