[git commit prelink 1/1] config parser: do not assume that realloc return same pointer

Natanael Copa natanael.copa at gmail.com
Sun Nov 28 19:50:38 UTC 2010


commit: http://git.uclibc.org/uClibc/commit/?id=54187ed0f082d145955a932f67259668dd038f65
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/prelink

We need to update the parser->line pointer on realloc and do not
initialize the token array til after the potensial realloc in
bb_get_chunk_with_continuation().

While here, also replace a realloc() with malloc() where pointer always
is NULL.

Signed-off-by: Natanael Copa <natanael.copa at gmail.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 libc/misc/internals/parse_config.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/libc/misc/internals/parse_config.c b/libc/misc/internals/parse_config.c
index 8fa324e..6734f35 100644
--- a/libc/misc/internals/parse_config.c
+++ b/libc/misc/internals/parse_config.c
@@ -78,6 +78,7 @@ static off_t bb_get_chunk_with_continuation(parser_t* parsr)
 			 parsr->line_len += PAGE_SIZE;
 			 parsr->data = realloc(parsr->data,
 								   parsr->data_len + parsr->line_len);
+			parsr->line = parsr->data + parsr->data_len;
 		}
 	}
 	return pos;
@@ -186,23 +187,21 @@ again:
 			parser->line_len = 81;
 		if (parser->data_len == 0)
 			parser->data_len += 1 + ntokens * sizeof(char *);
-		parser->data = realloc(parser->data,
-								parser->data_len + parser->line_len);
+		parser->data = malloc(parser->data_len + parser->line_len);
 		if (parser->data == NULL)
 			return 0;
 		parser->allocated |= 1;
 	} /* else { assert(parser->data_len > 0); } */
 	if (parser->line == NULL)
 		parser->line = parser->data + parser->data_len;
-	if (*tokens == NULL)
-		*tokens = (char **) parser->data;
-	memset(*tokens, 0, sizeof(*tokens[0]) * ntokens);
 	/*config_free_data(parser);*/
 
 	/* Read one line (handling continuations with backslash) */
 	len = bb_get_chunk_with_continuation(parser);
 	if (len == -1)
 		return 0;
+	*tokens = (char **) parser->data;
+	memset(*tokens, 0, sizeof(*tokens[0]) * ntokens);
 	line = parser->line;
 
 	/* Skip multiple token-delimiters in the start of line? */
-- 
1.7.2.2



More information about the uClibc-cvs mailing list