check_sha1_signature: check return value from read_istream
authorJeff King <peff@peff.net>
Mon, 25 Mar 2013 20:17:17 +0000 (16:17 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Mar 2013 20:46:55 +0000 (13:46 -0700)
It's possible for read_istream to return an error, in which
case we just end up in an infinite loop (aside from EOF, we
do not even look at the result, but just feed it straight
into our running hash).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c

index 16967d3b9a86dc481a5161f0a98220e05790ca01..0b99f336e62256606f3fffc3eaf0ee7727d428c5 100644 (file)
@@ -1266,6 +1266,10 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
                char buf[1024 * 16];
                ssize_t readlen = read_istream(st, buf, sizeof(buf));
 
+               if (readlen < 0) {
+                       close_istream(st);
+                       return -1;
+               }
                if (!readlen)
                        break;
                git_SHA1_Update(&c, buf, readlen);