Blame SOURCES/ncompress-4.2.4.4-filenamelen.patch

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