summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2008-01-04 17:37:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-01-04 20:28:58 (GMT)
commit872c930dcb048c1a2b50e6ce881c521dcee15e23 (patch)
treeccb4bc3d4d196327513108e59e3aeb76bfeeddbf /transport.c
parent95bf4bd4f7280312571e642339f3571310d0d660 (diff)
downloadgit-872c930dcb048c1a2b50e6ce881c521dcee15e23.zip
git-872c930dcb048c1a2b50e6ce881c521dcee15e23.tar.gz
git-872c930dcb048c1a2b50e6ce881c521dcee15e23.tar.bz2
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>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/transport.c b/transport.c
index 4e151a9..babaa21 100644
--- a/transport.c
+++ b/transport.c
@@ -118,7 +118,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
if (hexval(buffer[0]) > 0xf)
continue;
len = strlen(buffer);
- if (buffer[len - 1] == '\n')
+ if (len && buffer[len - 1] == '\n')
buffer[--len] = '\0';
if (len < 41)
continue;