Skip to content

Commit c146374

Browse files
committed
revparse: detect out-of-memory cases when parsing curly brace contents
When extracting curly braces (e.g. the "upstream" part in "HEAD@{upstream}"), we put the curly braces' contents into a `git_buf` structure, but don't check the return value of `git_buf_putc`. So when we run out-of-memory, we'll use a partially filled buffer without noticing. Let's fix this issue by checking `git_buf_putc`'s return value.
1 parent c708e5e commit c146374

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/revparse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *
537537
if (spec[*pos] == '\0')
538538
return GIT_EINVALIDSPEC;
539539

540-
git_buf_putc(buf, spec[(*pos)++]);
540+
if (git_buf_putc(buf, spec[(*pos)++]) < 0)
541+
return -1;
541542
}
542543

543544
(*pos)++;

0 commit comments

Comments
 (0)