diff options
author | Eric Blake <ebb9@byu.net> | 2009-02-18 12:03:03 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-02-18 14:54:07 -0700 |
commit | 4cd6b69ea7747052d12c0f2c4c28be082b030b00 (patch) | |
tree | 10223bde2680e6e4abeb8be88bd1f1cebcd96600 /m4 | |
parent | 7c675b594080836fde2aa524ef7aa504c46e5069 (diff) | |
download | m4-4cd6b69ea7747052d12c0f2c4c28be082b030b00.tar.gz |
Avoid risk of stack overflow.
* m4/output.c (insert_file): Avoid stack allocation of large
buffer.
Signed-off-by: Eric Blake <ebb9@byu.net>
(cherry picked from commit 01f216c3c98d41db7878b18c93d23e8dc38d8643)
Diffstat (limited to 'm4')
-rw-r--r-- | m4/output.c | 8 |
1 files changed, 4 insertions, 4 deletions
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")); |