summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-03-09 15:28:59 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-03-10 17:25:59 +0000
commit3cbc35945ac4a3a03e90da0d0586c877a3e6e952 (patch)
treeacada0780a977c339975cd39fce642e7a9509fcd
parent547f8f9c330476a0477db0a3832f10a3b7137439 (diff)
downloadlibgit2-ethomson/ntlm.tar.gz
http: detect closed connection by the serverethomson/ntlm
If the server closes the connection unexpected, `recv` will return 0. Process what we can in case there was a complete response. If there was not, error.
-rw-r--r--src/transports/http.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/transports/http.c b/src/transports/http.c
index 061c9d091..1d9b807a3 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -1102,6 +1102,7 @@ static int http_stream_read(
http_subtransport *t = OWNING_SUBTRANSPORT(s);
parser_context ctx;
size_t bytes_parsed;
+ int connected = 1;
bool auth_replay;
replay:
@@ -1150,7 +1151,7 @@ replay:
s->received_response = 1;
}
- while (!*bytes_read && !t->parse_finished) {
+ while (connected && !*bytes_read && !t->parse_finished) {
size_t data_offset;
/*
@@ -1169,7 +1170,7 @@ replay:
data_offset = t->parse_buffer.offset;
- if (gitno_recv(&t->parse_buffer) < 0)
+ if ((connected = gitno_recv(&t->parse_buffer)) < 0)
return -1;
/*
@@ -1212,6 +1213,12 @@ replay:
}
}
+ /* read returned 0; we got an eof before a complete message */
+ if (!*bytes_read && !t->parse_finished) {
+ git_error_set(GIT_ERROR_NET, "premature end of file");
+ return -1;
+ }
+
if (auth_replay) {
int error;