diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-08-08 10:47:29 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-08-23 12:54:01 +0200 |
commit | c2dd895a8df51d0a012e7780380f46bd60dde432 (patch) | |
tree | 754f859f1648a5359b02351bcf4f91b223b54477 /src/transports/winhttp.c | |
parent | 08699541eaf25c3e186aed25157aeaa518dd2e65 (diff) | |
download | libgit2-c2dd895a8df51d0a012e7780380f46bd60dde432.tar.gz |
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`.
Diffstat (limited to 'src/transports/winhttp.c')
-rw-r--r-- | src/transports/winhttp.c | 5 |
1 files changed, 4 insertions, 1 deletions
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; |