From 9b366f41367f717d8ddd9909fdc710b92f92a16c Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 20 Jul 2008 17:50:58 +0000 Subject: libbb/parse_config.c: fix small buglet (by Vladimir) --- libbb/parse_config.c | 4 +++- testsuite/parse.tests | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/libbb/parse_config.c b/libbb/parse_config.c index 68caa2c..3174a64 100644 --- a/libbb/parse_config.c +++ b/libbb/parse_config.c @@ -199,7 +199,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const } else { // vanilla token. cut the line at the first delim q = line + strcspn(line, delims); - *q++ = '\0'; + if (*q) // watch out: do not step past the line end! + *q++ = '\0'; } // pin token if ((flags & (PARSE_DONT_REDUCE|PARSE_DONT_TRIM)) || *line) { @@ -207,6 +208,7 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const tokens[ii++] = line; } line = q; + //bb_info_msg("A[%s]", line); } if (ii < mintokens) diff --git a/testsuite/parse.tests b/testsuite/parse.tests index 1b43f9c..06be8d2 100755 --- a/testsuite/parse.tests +++ b/testsuite/parse.tests @@ -23,7 +23,7 @@ testing "notrim" \ "-" \ " sda 0:0 644 @echo @echo TEST \n" -FILE=__parse.fstab +FILE=__parse cat >$FILE <$FILE.res <$FILE.res <