aboutsummaryrefslogtreecommitdiff
path: root/libbb/parse_config.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-06-26 04:00:52 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-06-26 04:00:52 +0200
commit63144be7eae8757b0e0d81ff6fa8adb0b26ff7c1 (patch)
tree72403548ea98908b32a67445e321f5f0e3d4f9e1 /libbb/parse_config.c
parent1fcbff2fac490f5665fc1ed13ddad766a8879f3b (diff)
downloadbusybox-63144be7eae8757b0e0d81ff6fa8adb0b26ff7c1.tar.gz
universal parser: do not leak parser->data
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/parse_config.c')
-rw-r--r--libbb/parse_config.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index c511d97fb..b7c3a00e0 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -128,8 +128,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
int ntokens, mintokens;
int t, len;
- ntokens = flags & 0xFF;
- mintokens = (flags & 0xFF00) >> 8;
+ ntokens = (uint8_t)flags;
+ mintokens = (uint8_t)(flags >> 8);
if (parser == NULL)
return 0;
@@ -159,7 +159,8 @@ again:
parser->data = xstrdup(line);
/* Tokenize the line */
- for (t = 0; *line && *line != delims[0] && t < ntokens; t++) {
+ t = 0;
+ do {
/* Pin token */
tokens[t] = line;
@@ -179,10 +180,10 @@ again:
}
/* Token not terminated? */
- if (line[0] == delims[0])
+ if (*line == delims[0])
*line = '\0';
- else if (line[0] != '\0')
- *(line++) = '\0';
+ else if (*line != '\0')
+ *line++ = '\0';
#if 0 /* unused so far */
if (flags & PARSE_ESCAPE) {
@@ -201,17 +202,20 @@ again:
*to = '\0';
}
#endif
-
/* Skip possible delimiters */
if (flags & PARSE_COLLAPSE)
line += strspn(line, delims + 1);
- }
+
+ t++;
+ } while (*line && *line != delims[0] && t < ntokens);
if (t < mintokens) {
bb_error_msg("bad line %u: %d tokens found, %d needed",
parser->lineno, t, mintokens);
if (flags & PARSE_MIN_DIE)
xfunc_die();
+ if (flags & PARSE_KEEP_COPY)
+ free(parser->data);
goto again;
}