diff options
author | David Rientjes <rientjes@google.com> | 2006-08-17 22:54:57 +0400 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-08-18 01:23:53 +0400 |
commit | a89fccd28197fa179828c8596791ff16e2268d20 (patch) | |
tree | 4a6c2b256a986fc221c0e1d5fa7d910f3b31eee8 /sha1_file.c | |
parent | d4baf9eaf47ea1ba204f1ab5ecd22326913dd081 (diff) |
Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
Introduces global inline:
hashcmp(const unsigned char *sha1, const unsigned char *sha2)
Uses memcmp for comparison and returns the result based on the length of
the hash name (a future runtime decision).
Acked-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sha1_file.c b/sha1_file.c index 18dece46b1..04f7f94d21 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -485,10 +485,10 @@ int use_packed_git(struct packed_git *p) /* Check if the pack file matches with the index file. * this is cheap. */ - if (memcmp((char*)(p->index_base) + p->index_size - 40, - (char *) p->pack_base + p->pack_size - 20, - 20)) { - + if (hashcmp((unsigned char *)(p->index_base) + + p->index_size - 40, + (unsigned char *)p->pack_base + + p->pack_size - 20)) { die("packfile %s does not match index.", p->pack_name); } } @@ -643,7 +643,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long siz SHA1_Update(&c, header, 1+sprintf(header, "%s %lu", type, size)); SHA1_Update(&c, map, size); SHA1_Final(real_sha1, &c); - return memcmp(sha1, real_sha1, 20) ? -1 : 0; + return hashcmp(sha1, real_sha1) ? -1 : 0; } void *map_sha1_file(const unsigned char *sha1, unsigned long *size) @@ -941,7 +941,7 @@ int check_reuse_pack_delta(struct packed_git *p, unsigned long offset, ptr = unpack_object_header(p, ptr, kindp, sizep); if (*kindp != OBJ_DELTA) goto done; - memcpy(base, (char *) p->pack_base + ptr, 20); + memcpy(base, (unsigned char *) p->pack_base + ptr, 20); status = 0; done: unuse_packed_git(p); @@ -1206,7 +1206,7 @@ int find_pack_entry_one(const unsigned char *sha1, do { int mi = (lo + hi) / 2; - int cmp = memcmp((char *) index + (24 * mi) + 4, sha1, 20); + int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1); if (!cmp) { e->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi)))); memcpy(e->sha1, sha1, 20); @@ -1715,7 +1715,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer, unlink(tmpfile); return error("File %s corrupted", sha1_to_hex(sha1)); } - if (memcmp(sha1, real_sha1, 20)) { + if (hashcmp(sha1, real_sha1)) { unlink(tmpfile); return error("File %s has bad hash", sha1_to_hex(sha1)); } |