components/groff/patches/grn-main.cpp.patch
author Petr Sumbera <petr.sumbera@oracle.com>
Thu, 28 Apr 2016 01:48:52 -0700
changeset 5873 1b57430f3995
parent 1883 bb9b7c4fd9b7
permissions -rw-r--r--
23195793 Upgrade Wireshark to version 2.0.3 23182108 problem in UTILITY/WIRESHARK 23182028 problem in UTILITY/WIRESHARK

Prevent grn from core dumping when given more than 50 command lines
arguments (CR #17621259).

This fix is not currently in the latest groff sources, and has been passed
upstream.

--- groff-1.22.2/src/preproc/grn/main.cpp.orig	2014-01-23 16:54:20.488279600 -0800
+++ groff-1.22.2/src/preproc/grn/main.cpp	2014-01-23 16:58:22.672837243 -0800
@@ -92,6 +92,8 @@
 extern POINT *PTInit();
 extern POINT *PTMakePoint(double x, double y, POINT **pplist);
 
+#define INIT_FILE_SIZE 50  /* Initial size of array of files from cmd line. */
+#define FILE_SIZE_INCR 50  /* Amount to increase array of files by. */
 
 #define SUN_SCALEFACTOR 0.70
 
@@ -244,6 +246,25 @@
 }
 
 
+/* Add a new file entry in the array, expanding array if needs be. */
+
+char **
+add_file(char **file, char *new_file, int *count, int *cur_size)
+{
+  if (*count >= *cur_size) {
+    *cur_size += FILE_SIZE_INCR;
+    file = (char **) realloc((char **) file, *cur_size * sizeof(char *));
+    if (file == NULL) {
+      fatal("unable to extend file array");
+    }
+  }
+  file[*count] = new_file;
+  *count += 1;
+
+  return file;
+}
+
+
 /*----------------------------------------------------------------------------*
  | Routine:	main (argument_count, argument_pointer)
  |
@@ -262,18 +283,22 @@
   register FILE *fp;
   register int k;
   register char c;
-  register int gfil = 0;
-  char *file[50];
+  int gfil = 0;
+  char **file = NULL;
+  int file_cur_size = INIT_FILE_SIZE;
   char *operand(int *argcp, char ***argvp);
 
+  if ((file = (char **) malloc(file_cur_size * sizeof(char *))) == NULL) {
+    fatal("unable to create file array");
+  }
   while (--argc) {
     if (**++argv != '-')
-      file[gfil++] = *argv;
+      file = add_file(file, *argv, &gfil, &file_cur_size);
     else
       switch (c = (*argv)[1]) {
 
       case 0:
-	file[gfil++] = NULL;
+	file = add_file(file, NULL, &gfil, &file_cur_size);
 	break;
 
       case 'C':		/* compatibility mode */