[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff-commit] [groff] 01/01: [grn] Prevent crash if more than 50 comman
From: |
Werner LEMBERG |
Subject: |
[Groff-commit] [groff] 01/01: [grn] Prevent crash if more than 50 command line arguments. |
Date: |
Wed, 12 Feb 2014 21:55:17 +0000 |
wl pushed a commit to branch master
in repository groff.
commit 4b0a4fccaa8a27ff87cc9ad75871a2e94b8d51c1
Author: Rich Burridge <address@hidden>
Date: Wed Feb 12 22:54:39 2014 +0100
[grn] Prevent crash if more than 50 command line arguments.
* src/preproc/grn/main.cpp (INIT_FILE_SIZE, FILE_SIZE_INCR): New
macros.
(add_file): New function.
(main): Use it to add file arguments.
---
ChangeLog | 9 +++++++++
src/preproc/grn/main.cpp | 36 ++++++++++++++++++++++++++++++++----
2 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5a9ba7f..178c998 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-02-12 Rich Burridge <address@hidden>
+
+ [grn] Prevent crash if more than 50 command line arguments.
+
+ * src/preproc/grn/main.cpp (INIT_FILE_SIZE, FILE_SIZE_INCR): New
+ macros.
+ (add_file): New function.
+ (main): Use it to add file arguments.
+
2014-01-29 Ulrich Spörlein <address@hidden>
* tmac/doc-common: Add even more DragonFlyBSD releases.
diff --git a/src/preproc/grn/main.cpp b/src/preproc/grn/main.cpp
index d6ae754..55fc27a 100644
--- a/src/preproc/grn/main.cpp
+++ b/src/preproc/grn/main.cpp
@@ -92,6 +92,8 @@ extern ELT *DBRead(register FILE *file);
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,28 @@ usage(FILE *stream)
}
+/* 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 +286,22 @@ main(int argc,
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 */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Groff-commit] [groff] 01/01: [grn] Prevent crash if more than 50 command line arguments.,
Werner LEMBERG <=