Skip to content

Commit 0869954

Browse files
committed
trailer: check for memory allocation errors
The "trailer.c" code has been copied mostly verbatim from git.git with minor adjustments, only. As git.git's `xmalloc` function, which aborts on memory allocation errors, has been swapped out for `git_malloc`, which doesn't abort, we may inadvertently access `NULL` pointers. Add checks to fix this.
1 parent 8c7d976 commit 0869954

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/trailer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ static char *extract_trailer_block(const char *message, size_t* len)
267267
size_t trailer_len = trailer_end - trailer_start;
268268

269269
char *buffer = git__malloc(trailer_len + 1);
270+
if (buffer == NULL)
271+
return NULL;
272+
270273
memcpy(buffer, message + trailer_start, trailer_len);
271274
buffer[trailer_len] = 0;
272275

@@ -302,6 +305,8 @@ int git_message_trailers(git_message_trailer_array *trailer_arr, const char *mes
302305

303306
size_t trailer_len;
304307
char *trailer = extract_trailer_block(message, &trailer_len);
308+
if (trailer == NULL)
309+
return -1;
305310

306311
for (ptr = trailer;;) {
307312
switch (state) {

0 commit comments

Comments
 (0)