@matheusbsbs / matheus-bagliano / commits / ae9c86f2b6
Fork 0

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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>

Rene Scharfe committed Aug 10, 2006 at 17:02 UTC ae9c86f2b6c89a3a0991209dae51086f884959c0
1 file changed +9 -7
verify-pack.c
+9 -7
@@ -1,11 +1,16 @@
1 #include "cache.h"
2 #include "pack.h"
3
4 -static int verify_one_pack(char *arg, int verbose)
4 +static int verify_one_pack(const char *path, int verbose)
5 {
6 - int len = strlen(arg);
6 + char arg[PATH_MAX];
7 + int len;
8 struct packed_git *g;
8 -
9 +
10 + len = strlcpy(arg, path, PATH_MAX);
11 + if (len >= PATH_MAX)
12 + return error("name too long: %s", path);
13 +
14 while (1) {
15 /* Should name foo.idx, but foo.pack may be named;
16 * convert it to foo.idx
@@ -37,8 +42,6 @@ int main(int ac, char **av)
42 int nothing_done = 1;
43
44 while (1 < ac) {
40 - char path[PATH_MAX];
41 -
45 if (!no_more_options && av[1][0] == '-') {
46 if (!strcmp("-v", av[1]))
47 verbose = 1;
@@ -48,8 +51,7 @@ int main(int ac, char **av)
51 usage(verify_pack_usage);
52 }
53 else {
51 - strcpy(path, av[1]);
52 - if (verify_one_pack(path, verbose))
54 + if (verify_one_pack(av[1], verbose))
55 errs++;
56 nothing_done = 0;
57 }