Blame SOURCES/ncompress-4.2.4.4-filenamelen.patch

3ed5bf
diff --git a/compress42.c b/compress42.c
3ed5bf
index b3b3add..6878046 100644
3ed5bf
--- a/compress42.c
3ed5bf
+++ b/compress42.c
3ed5bf
@@ -141,6 +141,7 @@
3ed5bf
 #include	<sys/types.h>
3ed5bf
 #include	<sys/stat.h>
3ed5bf
 #include	<errno.h>
3ed5bf
+#include	<string.h>
3ed5bf
 
3ed5bf
 #ifdef DIRENT
3ed5bf
 #	include	<dirent.h>
3ed5bf
@@ -214,7 +215,7 @@
3ed5bf
 #	define	OBUFSIZ	BUFSIZ	/* Default output buffer size							*/
3ed5bf
 #endif
3ed5bf
 
3ed5bf
-#define MAXPATHLEN 1024		/* MAXPATHLEN - maximum length of a pathname we allow 	*/
3ed5bf
+#define MAXPATHLEN PATH_MAX 		/* MAXPATHLEN - maximum length of a pathname we allow 	*/
3ed5bf
 #define	SIZE_INNER_LOOP		256	/* Size of the inter (fast) compress loop			*/
3ed5bf
 
3ed5bf
 							/* Defines for third byte of header 					*/
3ed5bf
@@ -701,6 +702,7 @@ main(argc, argv)
3ed5bf
 	{
3ed5bf
     	REG3	char		**filelist;
3ed5bf
 		REG4	char		**fileptr;
3ed5bf
+	int i;
3ed5bf
 
3ed5bf
     	if (fgnd_flag = (signal(SIGINT, SIG_IGN) != SIG_IGN))
3ed5bf
 			signal(SIGINT, (SIG_TYPE)abort_compress);
3ed5bf
@@ -714,13 +716,18 @@ main(argc, argv)
3ed5bf
     	nomagic = 1;	/* Original didn't have a magic number */
3ed5bf
 #endif
3ed5bf
 
3ed5bf
-    	filelist = (char **)malloc(argc*sizeof(char *));
3ed5bf
+	for (i=0; i
3ed5bf
+		if (strlen(argv[i])>(MAXPATHLEN-1)) {
3ed5bf
+			fprintf(stderr,"Filename too long\n");
3ed5bf
+			exit(1);
3ed5bf
+		}
3ed5bf
+	}
3ed5bf
+	filelist = fileptr = (char **)malloc(argc*sizeof(char *));
3ed5bf
     	if (filelist == NULL)
3ed5bf
 		{
3ed5bf
 			fprintf(stderr, "Cannot allocate memory for file list.\n");
3ed5bf
 			exit (1);
3ed5bf
 		}
3ed5bf
-    	fileptr = filelist;
3ed5bf
     	*filelist = NULL;
3ed5bf
 
3ed5bf
     	if((progname = strrchr(argv[0], '/')) != 0)
3ed5bf
@@ -860,7 +867,9 @@ nextarg:	continue;
3ed5bf
 				decompress(0, 1);
3ed5bf
 		}
3ed5bf
 
3ed5bf
+		free(filelist);
3ed5bf
 		exit((exit_code== -1) ? 1:exit_code);
3ed5bf
+		return 0;
3ed5bf
 	}
3ed5bf
 
3ed5bf
 void