summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2021-08-09 22:48:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-08-10 18:37:36 (GMT)
commitc4d5907324394228e08a42589a044fa14d7ffdcc (patch)
tree24cbee8881a34f847b4c1ce74511ddfed2c6121b /range-diff.c
parent7c86d365da1fe2e02f568365f0ae45deb2bd412e (diff)
downloadgit-c4d5907324394228e08a42589a044fa14d7ffdcc.zip
git-c4d5907324394228e08a42589a044fa14d7ffdcc.tar.gz
git-c4d5907324394228e08a42589a044fa14d7ffdcc.tar.bz2
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 <peff@peff.net> Acked-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/range-diff.c b/range-diff.c
index 87e82ee..012b4ea 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -38,7 +38,7 @@ static int read_patches(const char *range, struct string_list *list,
struct patch_util *util = NULL;
int in_header = 1;
char *line, *current_filename = NULL;
- int len;
+ ssize_t len;
size_t size;
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",