[PATCH v2 2/2] sha1_file: use strncmp for string comparison
- From
René Scharfe <l.s.r@web.de>
- Date
- Jun 29, 2014, 05:56 UTC
- Message-ID
- <53AFAA89.6050200@web.de>
- In-Reply-To
- <53AFA775.1090900@web.de>
Avoid overrunning the existing pack name (p->pack_name, a C string) in the case that the new path is longer by using strncmp instead of memcmp for comparing. While at it, replace the magic constant 4 with a strlen call to document its meaning.
Signed-off-by: Rene Scharfe <l.s.r@web.de> --- No changes from intial round.
sha1_file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sha1_file.c b/sha1_file.c index 394fa45..8adab14 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1207,7 +1207,8 @@ static void prepare_packed_git_one(char *objdir, int local) if (has_extension(de->d_name, ".idx")) { /* Don't reopen a pack we already have. */ for (p = packed_git; p; p = p->next) { - if (!memcmp(path.buf, p->pack_name, path.len - 4)) + if (!strncmp(path.buf, p->pack_name, + path.len - strlen(".idx"))) break; } if (p == NULL &&
-- 2.0.0