From ef1d779d7b82ead5c66c4f0bd103593afa08003e Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 21 May 2021 17:29:38 -0400 Subject: [PATCH] Don't try to write empty early data in the tool. We'll return 0 and get confused. (Negotiating early data and not using it is plausible if, say, the client preconnects but gets a ServerHello before any request binds the socket.) Change-Id: I94d458e18c58223f73c9340cac06e5ec5f8c84a0 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/47684 Reviewed-by: Adam Langley --- tool/client.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tool/client.cc b/tool/client.cc index 31378d6b2..a36d7ead7 100644 --- a/tool/client.cc +++ b/tool/client.cc @@ -313,15 +313,17 @@ static bool DoConnection(SSL_CTX *ctx, } early_data = std::string(data.begin(), data.end()); } - int ed_size = early_data.size(); - int ssl_ret = SSL_write(ssl.get(), early_data.data(), ed_size); - if (ssl_ret <= 0) { - int ssl_err = SSL_get_error(ssl.get(), ssl_ret); - PrintSSLError(stderr, "Error while writing", ssl_err, ssl_ret); - return false; - } else if (ssl_ret != ed_size) { - fprintf(stderr, "Short write from SSL_write.\n"); - return false; + if (!early_data.empty()) { + int ed_size = early_data.size(); + int ssl_ret = SSL_write(ssl.get(), early_data.data(), ed_size); + if (ssl_ret <= 0) { + int ssl_err = SSL_get_error(ssl.get(), ssl_ret); + PrintSSLError(stderr, "Error while writing", ssl_err, ssl_ret); + return false; + } else if (ssl_ret != ed_size) { + fprintf(stderr, "Short write from SSL_write.\n"); + return false; + } } }