From c2dd895a8df51d0a012e7780380f46bd60dde432 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 8 Aug 2019 10:47:29 +0200 Subject: transports: http: check for memory allocation failures When allocating a chunk that is used to write to HTTP streams, we do not check for memory allocation errors. This may lead us to write to a `NULL` pointer and thus cause a segfault. Fix this by adding a call to `GIT_ERROR_CHECK_ALLOC`. --- src/transports/winhttp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/transports/winhttp.c') diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 7fc6b7059..3cab5d700 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -1011,6 +1011,7 @@ replay: } buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE); + GIT_ERROR_CHECK_ALLOC(buffer); while (len > 0) { DWORD bytes_written; @@ -1392,8 +1393,10 @@ static int winhttp_stream_write_chunked( /* Append as much to the buffer as we can */ int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len); - if (!s->chunk_buffer) + if (!s->chunk_buffer) { s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE); + GIT_ERROR_CHECK_ALLOC(s->chunk_buffer); + } memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count); s->chunk_buffer_len += count; -- cgit v1.2.1