Blame SOURCES/ncompress-4.2.4.4-filenamelen.patch

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