61 lines
1.6 KiB
Diff
61 lines
1.6 KiB
Diff
diff --git a/compress42.c b/compress42.c
|
|
index bec7a2f..ff437e5 100644
|
|
--- a/compress42.c
|
|
+++ b/compress42.c
|
|
@@ -151,6 +151,7 @@
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <errno.h>
|
|
+#include <string.h>
|
|
|
|
#if !defined(DOS) && !defined(WINDOWS)
|
|
# include <unistd.h>
|
|
@@ -229,6 +230,8 @@ static inline access(const char *pathname, int mode)
|
|
# define OBUFSIZ BUFSIZ /* Default output buffer size */
|
|
#endif
|
|
|
|
+#define MAXPATHLEN PATH_MAX /* MAXPATHLEN - maximum length of a pathname we allow */
|
|
+
|
|
/* Defines for third byte of header */
|
|
#define MAGIC_1 (char_type)'\037'/* First byte of compressed file */
|
|
#define MAGIC_2 (char_type)'\235'/* Second byte of compressed file */
|
|
@@ -713,6 +716,7 @@ main(argc, argv)
|
|
REG3 char **filelist;
|
|
REG4 char **fileptr;
|
|
int seen_double_dash = 0;
|
|
+ int i = 0;
|
|
|
|
#ifdef SIGINT
|
|
if ((fgnd_flag = (signal(SIGINT, SIG_IGN)) != SIG_IGN))
|
|
@@ -730,13 +734,18 @@ main(argc, argv)
|
|
nomagic = 1; /* Original didn't have a magic number */
|
|
#endif
|
|
|
|
- filelist = (char **)malloc(argc*sizeof(char *));
|
|
+ for (i=0; i<argc; i++) {
|
|
+ if (strlen(argv[i])>(MAXPATHLEN-1)) {
|
|
+ fprintf(stderr,"Filename too long\n");
|
|
+ exit(1);
|
|
+ }
|
|
+ }
|
|
+ filelist = fileptr = (char **)malloc(argc*sizeof(char *));
|
|
if (filelist == NULL)
|
|
{
|
|
fprintf(stderr, "Cannot allocate memory for file list.\n");
|
|
exit (1);
|
|
}
|
|
- fileptr = filelist;
|
|
*filelist = NULL;
|
|
|
|
if((progname = strrchr(argv[0], '/')) != 0)
|
|
@@ -886,7 +895,9 @@ nextarg: continue;
|
|
decompress(0, 1);
|
|
}
|
|
|
|
+ free(filelist);
|
|
exit((exit_code== -1) ? 1:exit_code);
|
|
+ return 0;
|
|
}
|
|
|
|
void
|