From 872c930dcb048c1a2b50e6ce881c521dcee15e23 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 4 Jan 2008 18:37:41 +0100 Subject: Don't access line[-1] for a zero-length "line" from fgets. A NUL byte at beginning of file, or just after a newline would provoke an invalid buf[-1] access in a few places. * builtin-grep.c (cmd_grep): Don't access buf[-1]. * builtin-pack-objects.c (get_object_list): Likewise. * builtin-rev-list.c (read_revisions_from_stdin): Likewise. * bundle.c (read_bundle_header): Likewise. * server-info.c (read_pack_info_file): Likewise. * transport.c (insert_packed_refs): Likewise. Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- builtin-rev-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-rev-list.c') diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 1cb5f6711..de80158fd 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -520,7 +520,7 @@ static void read_revisions_from_stdin(struct rev_info *revs) while (fgets(line, sizeof(line), stdin) != NULL) { int len = strlen(line); - if (line[len - 1] == '\n') + if (len && line[len - 1] == '\n') line[--len] = 0; if (!len) break; -- cgit v1.2.1