Skip to content

Commit c4d5907

Browse files
peffgitster
authored andcommitted
range-diff: use ssize_t for parsed "len" in read_patches()
As we iterate through the buffer containing git-log output, parsing lines, we use an "int" to store the size of an individual line. This should be a size_t, as we have no guarantee that there is not a malicious 2GB+ commit-message line in the output. Overflowing this integer probably doesn't do anything _too_ terrible. We are not using the value to size a buffer, so the worst case is probably an out-of-bounds read from before the array. But it's easy enough to fix. Note that we have to use ssize_t here, since we also store the length result from parse_git_diff_header(), which may return a negative value for error. That function actually returns an int itself, which has a similar overflow problem, but I'll leave that for another day. Much of the apply.c code uses ints and should be converted as a whole; in the meantime, a negative return from parse_git_diff_header() will be interpreted as an error, and we'll bail (so we can't handle such a case, but given that it's likely to be malicious anyway, the important thing is we don't have any memory errors). Signed-off-by: Jeff King <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c86d36 commit c4d5907

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

range-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int read_patches(const char *range, struct string_list *list,
3838
struct patch_util *util = NULL;
3939
int in_header = 1;
4040
char *line, *current_filename = NULL;
41-
int len;
41+
ssize_t len;
4242
size_t size;
4343

4444
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",

0 commit comments

Comments
 (0)