From 4cd6b69ea7747052d12c0f2c4c28be082b030b00 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 18 Feb 2009 12:03:03 -0700 Subject: Avoid risk of stack overflow. * m4/output.c (insert_file): Avoid stack allocation of large buffer. Signed-off-by: Eric Blake (cherry picked from commit 01f216c3c98d41db7878b18c93d23e8dc38d8643) --- ChangeLog | 4 ++++ m4/output.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b897d597..3f98309c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-02-18 Eric Blake + 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")); -- cgit v1.2.1