[PATCH v3 08/11] Extract verify_pack_index for reuse from verify_pack

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Shawn O. Pearce
Date: Saturday, April 17, 2010 - 1:07 pm

The dumb HTTP transport should verify an index is completely valid
before trying to use it.  That requires checking the header/footer
but also checking the complete content SHA-1.  All of this logic is
already in the front half of verify_pack, so pull it out into a new
function that can be reused.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 pack-check.c |   15 ++++++++++++---
 pack.h       |    1 +
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/pack-check.c b/pack-check.c
index 166ca70..395fb95 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -133,14 +133,13 @@ static int verify_packfile(struct packed_git *p,
 	return err;
 }
 
-int verify_pack(struct packed_git *p)
+int verify_pack_index(struct packed_git *p)
 {
 	off_t index_size;
 	const unsigned char *index_base;
 	git_SHA_CTX ctx;
 	unsigned char sha1[20];
 	int err = 0;
-	struct pack_window *w_curs = NULL;
 
 	if (open_pack_index(p))
 		return error("packfile %s index not opened", p->pack_name);
@@ -154,8 +153,18 @@ int verify_pack(struct packed_git *p)
 	if (hashcmp(sha1, index_base + index_size - 20))
 		err = error("Packfile index for %s SHA1 mismatch",
 			    p->pack_name);
+	return err;
+}
+
+int verify_pack(struct packed_git *p)
+{
+	int err = 0;
+	struct pack_window *w_curs = NULL;
+
+	err |= verify_pack_index(p);
+	if (!p->index_data)
+		return -1;
 
-	/* Verify pack file */
 	err |= verify_packfile(p, &w_curs);
 	unuse_pack(&w_curs);
 
diff --git a/pack.h b/pack.h
index d268c01..bb27576 100644
--- a/pack.h
+++ b/pack.h
@@ -57,6 +57,7 @@ struct pack_idx_entry {
 
 extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
 extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
+extern int verify_pack_index(struct packed_git *);
 extern int verify_pack(struct packed_git *);
 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
 extern char *index_pack_lockfile(int fd);
-- 
1.7.1.rc1.269.ga27c7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
git fetch over http:// left my repo broken, Christian Halstrick, (Thu Apr 15, 2:51 am)
Re: git fetch over http:// left my repo broken, Michael J Gruber, (Thu Apr 15, 2:58 am)
Re: git fetch over http:// left my repo broken, Ilari Liusvaara, (Thu Apr 15, 4:33 am)
Re: git fetch over http:// left my repo broken, Ilari Liusvaara, (Thu Apr 15, 4:43 am)
Re: git fetch over http:// left my repo broken, Shawn O. Pearce, (Thu Apr 15, 7:15 am)
[PATCH 0/6] detect dumb HTTP pack file corruption, Shawn O. Pearce, (Thu Apr 15, 12:09 pm)
[PATCH 1/6] http.c: Remove bad free of static block, Shawn O. Pearce, (Thu Apr 15, 12:09 pm)
[PATCH 2/6] t5550-http-fetch: Use subshell for repository ..., Shawn O. Pearce, (Thu Apr 15, 12:09 pm)
Re: [PATCH 0/6] detect dumb HTTP pack file corruption, Junio C Hamano, (Sat Apr 17, 10:56 am)
Re: [PATCH 0/6] detect dumb HTTP pack file corruption, Shawn O. Pearce, (Sat Apr 17, 12:11 pm)
Re: [PATCH v2 5/6] http-fetch: Use index-pack rather than ..., Shawn O. Pearce, (Sat Apr 17, 12:30 pm)
[PATCH v3 01/11] http.c: Remove bad free of static block, Shawn O. Pearce, (Sat Apr 17, 1:07 pm)
[PATCH v3 08/11] Extract verify_pack_index for reuse from ..., Shawn O. Pearce, (Sat Apr 17, 1:07 pm)
[PATCH v3 09/11] Allow parse_pack_index on temporary files, Shawn O. Pearce, (Sat Apr 17, 1:07 pm)
[PATCH v4 00/11] Resend sp/maint-dumb-http-pack-reidx, Shawn O. Pearce, (Mon Apr 19, 7:23 am)
[PATCH v4 09/11] Allow parse_pack_index on temporary files, Shawn O. Pearce, (Mon Apr 19, 7:23 am)
Re: [PATCH v4 00/11] Resend sp/maint-dumb-http-pack-reidx, Tay Ray Chuan, (Mon Apr 19, 7:46 am)
Re: [PATCH v4 00/11] Resend sp/maint-dumb-http-pack-reidx, Shawn O. Pearce, (Mon Apr 19, 7:49 am)
Re: [PATCH v4 00/11] Resend sp/maint-dumb-http-pack-reidx, Tay Ray Chuan, (Mon Apr 19, 9:33 pm)