diff options
author | Paul Smith <psmith@gnu.org> | 2003-01-30 07:49:17 +0000 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2003-01-30 07:49:17 +0000 |
commit | 1fa3db14684b18e50383be6a83a1f17f716b0788 (patch) | |
tree | 8ba77c275874f57a1429145c1f4381135bc80820 /read.c | |
parent | b7c728046e3f32cd93b04fa4a19a69cf6135e6e4 (diff) | |
download | gunmake-1fa3db14684b18e50383be6a83a1f17f716b0788.tar.gz |
Fix bug #2238: the read.c:eval() function was not entirely reentrant.
Apply patch #1022: fix a memory corruption on very long target-specific
variable definition lines.
Diffstat (limited to 'read.c')
-rw-r--r-- | read.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -452,8 +452,8 @@ eval_buffer (char *buffer) static int eval (struct ebuffer *ebuf, int set_default) { - static char *collapsed = 0; - static unsigned int collapsed_length = 0; + char *collapsed = 0; + unsigned int collapsed_length = 0; unsigned int commands_len = 200; char *commands; unsigned int commands_idx = 0; @@ -566,9 +566,7 @@ eval (struct ebuffer *ebuf, int set_default) if (collapsed_length < linelen+1) { collapsed_length = linelen+1; - if (collapsed != 0) - free (collapsed); - collapsed = (char *) xmalloc (collapsed_length); + collapsed = (char *) xrealloc (collapsed, collapsed_length); } strcpy (collapsed, line); /* Collapse continuation lines. */ @@ -1034,11 +1032,13 @@ eval (struct ebuffer *ebuf, int set_default) of the unparsed section of p2, for later. */ if (*lb_next != '\0') { - unsigned int l = p2 - variable_buffer; + unsigned int l = p - variable_buffer; + unsigned int l2 = p2 - variable_buffer; plen = strlen (p2); (void) variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1); - p2 = variable_buffer + l; + p = variable_buffer + l; + p2 = variable_buffer + l2; } /* See if it's an "override" or "export" keyword; if so see if what @@ -1069,9 +1069,11 @@ eval (struct ebuffer *ebuf, int set_default) after it. */ if (semip) { + unsigned int l = p - variable_buffer; *(--semip) = ';'; variable_buffer_output (p2 + strlen (p2), semip, strlen (semip)+1); + p = variable_buffer + l; } record_target_var (filenames, p, two_colon, v_origin, exported, fstart); @@ -1234,6 +1236,8 @@ eval (struct ebuffer *ebuf, int set_default) /* At eof, record the last rule. */ record_waiting_files (); + if (collapsed) + free ((char *) collapsed); free ((char *) commands); return 1; |