Blame SOURCES/ncompress-4.2.4.4-filenamelen.patch

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