|
1 Prevent grn from core dumping when given more than 50 command lines |
|
2 arguments (CR #17621259). |
|
3 |
|
4 This fix is not currently in the latest groff sources, and has been passed |
|
5 upstream. |
|
6 |
|
7 --- groff-1.22.2/src/preproc/grn/main.cpp.orig 2014-01-23 16:54:20.488279600 -0800 |
|
8 +++ groff-1.22.2/src/preproc/grn/main.cpp 2014-01-23 16:58:22.672837243 -0800 |
|
9 @@ -92,6 +92,8 @@ |
|
10 extern POINT *PTInit(); |
|
11 extern POINT *PTMakePoint(double x, double y, POINT **pplist); |
|
12 |
|
13 +#define INIT_FILE_SIZE 50 /* Initial size of array of files from cmd line. */ |
|
14 +#define FILE_SIZE_INCR 50 /* Amount to increase array of files by. */ |
|
15 |
|
16 #define SUN_SCALEFACTOR 0.70 |
|
17 |
|
18 @@ -244,6 +246,25 @@ |
|
19 } |
|
20 |
|
21 |
|
22 +/* Add a new file entry in the array, expanding array if needs be. */ |
|
23 + |
|
24 +char ** |
|
25 +add_file(char **file, char *new_file, int *count, int *cur_size) |
|
26 +{ |
|
27 + if (*count >= *cur_size) { |
|
28 + *cur_size += FILE_SIZE_INCR; |
|
29 + file = (char **) realloc((char **) file, *cur_size * sizeof(char *)); |
|
30 + if (file == NULL) { |
|
31 + fatal("unable to extend file array"); |
|
32 + } |
|
33 + } |
|
34 + file[*count] = new_file; |
|
35 + *count += 1; |
|
36 + |
|
37 + return file; |
|
38 +} |
|
39 + |
|
40 + |
|
41 /*----------------------------------------------------------------------------* |
|
42 | Routine: main (argument_count, argument_pointer) |
|
43 | |
|
44 @@ -262,18 +283,22 @@ |
|
45 register FILE *fp; |
|
46 register int k; |
|
47 register char c; |
|
48 - register int gfil = 0; |
|
49 - char *file[50]; |
|
50 + int gfil = 0; |
|
51 + char **file = NULL; |
|
52 + int file_cur_size = INIT_FILE_SIZE; |
|
53 char *operand(int *argcp, char ***argvp); |
|
54 |
|
55 + if ((file = (char **) malloc(file_cur_size * sizeof(char *))) == NULL) { |
|
56 + fatal("unable to create file array"); |
|
57 + } |
|
58 while (--argc) { |
|
59 if (**++argv != '-') |
|
60 - file[gfil++] = *argv; |
|
61 + file = add_file(file, *argv, &gfil, &file_cur_size); |
|
62 else |
|
63 switch (c = (*argv)[1]) { |
|
64 |
|
65 case 0: |
|
66 - file[gfil++] = NULL; |
|
67 + file = add_file(file, NULL, &gfil, &file_cur_size); |
|
68 break; |
|
69 |
|
70 case 'C': /* compatibility mode */ |