enmasse: check filename length

This commit is contained in:
Connor Lane Smith 2011-06-23 02:08:41 +01:00
parent 807d45aa80
commit a051bab859
2 changed files with 4 additions and 4 deletions

View File

@ -6,6 +6,7 @@ MIT/X Consortium License
© 2011 Rob Pilling <robpilling@gmail.com> © 2011 Rob Pilling <robpilling@gmail.com>
© 2011 Hiltjo Posthuma <hiltjo@codemadness.org> © 2011 Hiltjo Posthuma <hiltjo@codemadness.org>
© 2011 pancake <pancake@youterm.com> © 2011 pancake <pancake@youterm.com>
© 2011 Random832 <random832@fastmail.us>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

View File

@ -21,17 +21,16 @@ enmasse(int argc, char **argv, int (*fn)(const char *, const char *))
fnck(argv[0], argv[1], fn); fnck(argv[0], argv[1], fn);
return; return;
} }
else if(argc == 1)
dir = ".";
else else
dir = argv[--argc]; dir = (argc == 1) ? "." : argv[--argc];
if((size = pathconf(dir, _PC_PATH_MAX)) == -1) if((size = pathconf(dir, _PC_PATH_MAX)) == -1)
size = BUFSIZ; size = BUFSIZ;
if(!(buf = malloc(size))) if(!(buf = malloc(size)))
eprintf("malloc:"); eprintf("malloc:");
for(i = 0; i < argc; i++) { for(i = 0; i < argc; i++) {
snprintf(buf, size, "%s/%s", dir, basename(argv[i])); if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) > size)
eprintf("%s/%s: filename too long\n", dir, basename(argv[i]));
fnck(argv[i], buf, fn); fnck(argv[i], buf, fn);
} }
free(buf); free(buf);