diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | m4/output.c | 8 |
2 files changed, 8 insertions, 4 deletions
@@ -1,5 +1,9 @@ 2009-02-18 Eric Blake <ebb9@byu.net> + Avoid risk of stack overflow. + * m4/output.c (insert_file): Avoid stack allocation of large + buffer. + Synchronize THANKS with branch. * THANKS: Import more names. diff --git a/m4/output.c b/m4/output.c index baea127f..b2f6530a 100644 --- a/m4/output.c +++ b/m4/output.c @@ -1,6 +1,6 @@ /* GNU m4 -- A simple macro processor Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1998, 2002, 2004, - 2006, 2007, 2008 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU M4. @@ -887,16 +887,16 @@ m4_make_diversion (m4 *context, int divnum) static void insert_file (m4 *context, FILE *file, bool escaped) { - char buffer[COPY_BUFFER_SIZE]; + static char buffer[COPY_BUFFER_SIZE]; size_t length; char *str = buffer; bool first = true; assert (output_diversion); /* Insert output by big chunks. */ - for (;;) + while (1) { - length = fread (buffer, 1, COPY_BUFFER_SIZE, file); + length = fread (buffer, 1, sizeof buffer, file); if (ferror (file)) m4_error (context, EXIT_FAILURE, errno, NULL, _("reading inserted file")); |