summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-07-20 08:20:48 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2018-07-20 08:20:48 -0700
commitdc371e3c5903760cc2334a0acfac9bce04479773 (patch)
tree8038c5d54f41e458fdf5806ef98b54a225f45dd3
parentea9e2c1a4a16b572a3621d9bd7b1383365701b9e (diff)
downloadlibgit2-ethomson/wintls_fix.tar.gz
winhttp: retry erroneously failing requestsethomson/wintls_fix
Early Windows TLS 1.2 implementations have an issue during key exchange with OpenSSL implementations that cause negotiation to fail with the error "the buffer supplied to a function was too small." This is a transient error on the connection, so when that error is received, retry up to 5 times to create a connection to the remote server before actually giving up.
-rw-r--r--src/transports/winhttp.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 4eb8b427a..1a317f6a2 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -845,23 +845,27 @@ on_error:
static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
{
- if (ignore_length) {
- if (!WinHttpSendRequest(s->request,
- WINHTTP_NO_ADDITIONAL_HEADERS, 0,
- WINHTTP_NO_REQUEST_DATA, 0,
- WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH, 0)) {
- return -1;
- }
- } else {
- if (!WinHttpSendRequest(s->request,
- WINHTTP_NO_ADDITIONAL_HEADERS, 0,
- WINHTTP_NO_REQUEST_DATA, 0,
- len, 0)) {
- return -1;
+ int attempts;
+ bool success;
+
+ for (attempts = 0; attempts < 5; attempts++) {
+ if (ignore_length) {
+ success = WinHttpSendRequest(s->request,
+ WINHTTP_NO_ADDITIONAL_HEADERS, 0,
+ WINHTTP_NO_REQUEST_DATA, 0,
+ WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH, 0);
+ } else {
+ success = WinHttpSendRequest(s->request,
+ WINHTTP_NO_ADDITIONAL_HEADERS, 0,
+ WINHTTP_NO_REQUEST_DATA, 0,
+ len, 0);
}
+
+ if (success || GetLastError() != SEC_E_BUFFER_TOO_SMALL)
+ break;
}
- return 0;
+ return success ? 0 : -1;
}
static int send_request(winhttp_stream *s, size_t len, int ignore_length)