From ae9c86f2b6c89a3a0991209dae51086f884959c0 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Thu, 10 Aug 2006 17:02:32 +0200 Subject: [PATCH] git-verify-pack: more careful path handling Use strlcpy() to copy the filename into a buffer and complain if it doesn't fit. Also move the path buffer into verify_one_pack(); it is used only there. Now we can const'ify the first argument of this function. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- verify-pack.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/verify-pack.c b/verify-pack.c index 7201596bf9..77b3d282da 100644 --- a/verify-pack.c +++ b/verify-pack.c @@ -1,11 +1,16 @@ #include "cache.h" #include "pack.h" -static int verify_one_pack(char *arg, int verbose) +static int verify_one_pack(const char *path, int verbose) { - int len = strlen(arg); + char arg[PATH_MAX]; + int len; struct packed_git *g; - + + len = strlcpy(arg, path, PATH_MAX); + if (len >= PATH_MAX) + return error("name too long: %s", path); + while (1) { /* Should name foo.idx, but foo.pack may be named; * convert it to foo.idx @@ -37,8 +42,6 @@ int main(int ac, char **av) int nothing_done = 1; while (1 < ac) { - char path[PATH_MAX]; - if (!no_more_options && av[1][0] == '-') { if (!strcmp("-v", av[1])) verbose = 1; @@ -48,8 +51,7 @@ int main(int ac, char **av) usage(verify_pack_usage); } else { - strcpy(path, av[1]); - if (verify_one_pack(path, verbose)) + if (verify_one_pack(av[1], verbose)) errs++; nothing_done = 0; } -- 2.11.4.GIT