From f808d79994251a82420024924f435b2ba0ee78ac Mon Sep 17 00:00:00 2001 From: psmith Date: Sun, 2 Aug 2009 16:05:42 +0000 Subject: [PATCH] - Fix Savannah bug #27093 - Fix Savannah bug #27143 - Fix Savannah bug #23960 - Fix Savannah bug #27148 --- ChangeLog | 12 ++++++++++++ doc/make.texi | 18 +++++++++--------- expand.c | 21 +++++++++++++-------- job.c | 2 +- variable.c | 23 ++++++++++++++--------- 5 files changed, 49 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f0b073..26abd12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-08-01 Paul Smith + + * expand.c (expand_argument): If the argument is large enough use + xmalloc() instead of alloca(). Fixes Savannah bug #27143. + + * variable.c (do_variable_definition): Avoid using alloca() to + hold values, which can be large. Fixes Savannah bug #23960. + + * job.c (new_job): Use memmove() instead of strcpy() since both + pointers are in the same memory block. Fixes Savannah bug #27148. + Patch by Petr Machata. + 2009-07-29 Ralf Wildenhues * job.c (construct_command_argv_internal): Add "ulimit" and diff --git a/doc/make.texi b/doc/make.texi index 6a1b3f6..3397c89 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -4,7 +4,7 @@ @include version.texi @set EDITION 0.70 -@set RCSID $Id: make.texi,v 1.57 2009/08/01 22:09:40 psmith Exp $ +@set RCSID $Id: make.texi,v 1.58 2009/08/02 16:05:42 psmith Exp $ @settitle GNU @code{make} @setchapternewpage odd @@ -8478,7 +8478,7 @@ for full details on suffix rules. @pindex .o @pindex .c @file{@var{n}.o} is made automatically from @file{@var{n}.c} with -a recipe of the form @samp{$(CC) -c $(CPPFLAGS) $(CFLAGS)}.@refill +a recipe of the form @samp{$(CC) $(CPPFLAGS) $(CFLAGS) -c}.@refill @item Compiling C++ programs @cindex C++, rule to compile @@ -8488,7 +8488,7 @@ a recipe of the form @samp{$(CC) -c $(CPPFLAGS) $(CFLAGS)}.@refill @pindex .C @file{@var{n}.o} is made automatically from @file{@var{n}.cc}, @file{@var{n}.cpp}, or @file{@var{n}.C} with a recipe of the form -@samp{$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)}. We encourage you to use the +@samp{$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c}. We encourage you to use the suffix @samp{.cc} for C++ source files instead of @samp{.C}.@refill @item Compiling Pascal programs @@ -8496,7 +8496,7 @@ suffix @samp{.cc} for C++ source files instead of @samp{.C}.@refill @pindex pc @pindex .p @file{@var{n}.o} is made automatically from @file{@var{n}.p} -with the recipe @samp{$(PC) -c $(PFLAGS)}.@refill +with the recipe @samp{$(PC) $(PFLAGS) -c}.@refill @item Compiling Fortran and Ratfor programs @cindex Fortran, rule to compile @@ -8511,11 +8511,11 @@ Fortran compiler. The precise recipe used is as follows:@refill @table @samp @item .f -@samp{$(FC) -c $(FFLAGS)}. +@samp{$(FC) $(FFLAGS) -c}. @item .F -@samp{$(FC) -c $(FFLAGS) $(CPPFLAGS)}. +@samp{$(FC) $(FFLAGS) $(CPPFLAGS) -c}. @item .r -@samp{$(FC) -c $(FFLAGS) $(RFLAGS)}. +@samp{$(FC) $(FFLAGS) $(RFLAGS) -c}. @end table @item Preprocessing Fortran and Ratfor programs @@ -8526,9 +8526,9 @@ program. The precise recipe used is as follows:@refill @table @samp @item .F -@samp{$(FC) -F $(CPPFLAGS) $(FFLAGS)}. +@samp{$(FC) $(CPPFLAGS) $(FFLAGS) -F}. @item .r -@samp{$(FC) -F $(FFLAGS) $(RFLAGS)}. +@samp{$(FC) $(FFLAGS) $(RFLAGS) -F}. @end table @item Compiling Modula-2 programs diff --git a/expand.c b/expand.c index dc4ea47..b5d5338 100644 --- a/expand.c +++ b/expand.c @@ -438,7 +438,8 @@ variable_expand (const char *line) char * expand_argument (const char *str, const char *end) { - char *tmp; + char *tmp, *alloc = NULL; + char *r; if (str == end) return xstrdup(""); @@ -446,11 +447,20 @@ expand_argument (const char *str, const char *end) if (!end || *end == '\0') return allocated_variable_expand (str); - tmp = alloca (end - str + 1); + if (end - str + 1 > 1000) + tmp = alloc = xmalloc (end - str + 1); + else + tmp = alloca (end - str + 1); + memcpy (tmp, str, end - str); tmp[end - str] = '\0'; - return allocated_variable_expand (tmp); + r = allocated_variable_expand (tmp); + + if (alloc) + free (alloc); + + return r; } /* Expand LINE for FILE. Error messages refer to the file and line where @@ -563,11 +573,6 @@ allocated_variable_expand_for_file (const char *line, struct file *file) value = variable_expand_for_file (line, file); -#if 0 - /* Waste a little memory and save time. */ - value = xrealloc (value, strlen (value)) -#endif - variable_buffer = obuf; variable_buffer_length = olen; diff --git a/job.c b/job.c index b52868f..a4dadb1 100644 --- a/job.c +++ b/job.c @@ -1600,7 +1600,7 @@ new_job (struct file *file) /* There are no more references in this line to worry about. Copy the remaining uninteresting text to the output. */ if (out != in) - strcpy (out, in); + memmove (out, in, strlen (in) + 1); /* Finally, expand the line. */ lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i], diff --git a/variable.c b/variable.c index 92a96ec..10bbc54 100644 --- a/variable.c +++ b/variable.c @@ -1091,7 +1091,7 @@ do_variable_definition (const struct floc *flocp, const char *varname, unsigned int oldlen, vallen; const char *val; - char *tp; + char *tp = NULL; val = value; if (v->recursive) @@ -1104,15 +1104,17 @@ do_variable_definition (const struct floc *flocp, const char *varname, when it was set; and from the expanded new value. Allocate memory for the expansion as we may still need the rest of the buffer if we're looking at a target-specific variable. */ - val = alloc_value = allocated_variable_expand (val); + val = tp = allocated_variable_expand (val); oldlen = strlen (v->value); vallen = strlen (val); - tp = alloca (oldlen + 1 + vallen + 1); - memcpy (tp, v->value, oldlen); - tp[oldlen] = ' '; - memcpy (&tp[oldlen + 1], val, vallen + 1); - p = tp; + p = alloc_value = xmalloc (oldlen + 1 + vallen + 1); + memcpy (alloc_value, v->value, oldlen); + alloc_value[oldlen] = ' '; + memcpy (&alloc_value[oldlen + 1], val, vallen + 1); + + if (tp) + free (tp); } } } @@ -1220,10 +1222,10 @@ do_variable_definition (const struct floc *flocp, const char *varname, } else { - if (alloc_value) - free (alloc_value); + char *tp = alloc_value; alloc_value = allocated_variable_expand (p); + if (find_and_set_default_shell (alloc_value)) { v = define_variable_in_set (varname, strlen (varname), p, @@ -1236,6 +1238,9 @@ do_variable_definition (const struct floc *flocp, const char *varname, } else v = lookup_variable (varname, strlen (varname)); + + if (tp) + free (tp); } } else -- 2.11.4.GIT