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 <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
95bf4bd4f7
commit
872c930dcb
2
bundle.c
2
bundle.c
@ -48,7 +48,7 @@ int read_bundle_header(const char *path, struct bundle_header *header)
|
||||
: &header->references;
|
||||
char delim;
|
||||
|
||||
if (buffer[len - 1] == '\n')
|
||||
if (len && buffer[len - 1] == '\n')
|
||||
buffer[len - 1] = '\0';
|
||||
if (get_sha1_hex(buffer + offset, sha1)) {
|
||||
warning("unrecognized header: %s", buffer);
|
||||
|
Reference in New Issue
Block a user