Skip to content

Commit

Permalink
git-verify-pack: more careful path handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rene Scharfe authored and Junio C Hamano committed Aug 10, 2006
1 parent 6f05b57 commit ae9c86f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions verify-pack.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit ae9c86f

Please sign in to comment.