summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2020-06-01 23:53:55 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2020-06-03 10:11:04 +0100
commitbc61161b9879e03842a8df6764d40a49497e765e (patch)
treedbf0f638f37ccc3a0e05aed4b3b1a1771d00da15
parented045f0912ad6cbc512a98ebfbdd6ea08682f4ad (diff)
downloadlibgit2-bc61161b9879e03842a8df6764d40a49497e765e.tar.gz
httpclient: don't read more than the client wants
When `git_http_client_read_body` is invoked, it provides the size of the buffer that can be read into. This will be set as the parser context's `output_size` member. Use this as an upper limit on our reads, and ensure that we do not read more than the client requests.
-rw-r--r--src/transports/httpclient.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index af90129df..72a65f00f 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -1038,6 +1038,7 @@ on_error:
GIT_INLINE(int) client_read(git_http_client *client)
{
+ http_parser_context *parser_context = client->parser.data;
git_stream *stream;
char *buf = client->read_buf.ptr + client->read_buf.size;
size_t max_len;
@@ -1054,6 +1055,9 @@ GIT_INLINE(int) client_read(git_http_client *client)
max_len = client->read_buf.asize - client->read_buf.size;
max_len = min(max_len, INT_MAX);
+ if (parser_context->output_size)
+ max_len = min(max_len, parser_context->output_size);
+
if (max_len == 0) {
git_error_set(GIT_ERROR_HTTP, "no room in output buffer");
return -1;