Skip to content

Commit c2dd895

Browse files
committed
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`.
1 parent 0869954 commit c2dd895

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/transports/http.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,10 @@ static int http_stream_write_chunked(
13371337
/* Append as much to the buffer as we can */
13381338
int count = min(CHUNK_SIZE - s->chunk_buffer_len, len);
13391339

1340-
if (!s->chunk_buffer)
1340+
if (!s->chunk_buffer) {
13411341
s->chunk_buffer = git__malloc(CHUNK_SIZE);
1342+
GIT_ERROR_CHECK_ALLOC(s->chunk_buffer);
1343+
}
13421344

13431345
memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count);
13441346
s->chunk_buffer_len += count;

src/transports/winhttp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ static int winhttp_stream_read(
10111011
}
10121012

10131013
buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1014+
GIT_ERROR_CHECK_ALLOC(buffer);
10141015

10151016
while (len > 0) {
10161017
DWORD bytes_written;
@@ -1392,8 +1393,10 @@ static int winhttp_stream_write_chunked(
13921393
/* Append as much to the buffer as we can */
13931394
int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len);
13941395

1395-
if (!s->chunk_buffer)
1396+
if (!s->chunk_buffer) {
13961397
s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1398+
GIT_ERROR_CHECK_ALLOC(s->chunk_buffer);
1399+
}
13971400

13981401
memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count);
13991402
s->chunk_buffer_len += count;

0 commit comments

Comments
 (0)