do not read beyond end of malloc'd buffer
With diff.suppress-blank-empty=true, "git diff --word-diff" would output data that had been read from uninitialized heap memory. The problem was that fn_out_consume did not account for the possibility of a line with length 1, i.e., the empty context line that diff.suppress-blank-empty=true converts from " \n" to "\n". Since it assumed there would always be a prefix character (the space), it decremented "len" unconditionally, thus passing len=0 to emit_line, which would then blindly call emit_line_0 with len=-1 which would pass that value on to fwrite as SIZE_MAX. Boom. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5269edf170
commit
42536dd9b9
12
diff.c
12
diff.c
@ -1043,8 +1043,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
||||
emit_line(ecbdata->opt, plain, reset, line, len);
|
||||
fputs("~\n", ecbdata->opt->file);
|
||||
} else {
|
||||
/* don't print the prefix character */
|
||||
emit_line(ecbdata->opt, plain, reset, line+1, len-1);
|
||||
/*
|
||||
* Skip the prefix character, if any. With
|
||||
* diff_suppress_blank_empty, there may be
|
||||
* none.
|
||||
*/
|
||||
if (line[0] != '\n') {
|
||||
line++;
|
||||
len--;
|
||||
}
|
||||
emit_line(ecbdata->opt, plain, reset, line, len);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user