tests: add coverage-clean target

This new target removes gcda files so it is easier to review coverage
after code changes and previous runs are invalidated.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
test_cfg_lexer_subst: added static qualifiers to test functions

This is considered good style as the compiler warns if such a function
goes unused.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
test_cfg_lexer_subst: added further testcases to increase coverage

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lexer-subst: report an error if backtick expansion happens after backslash in a string

If we are substituting a string within double-quoted string and the
last character was a quote character, we can't really decide what to do.

The backslash character could protect the backtick, but double-backticks should
be used for those.

If we simply substituted the backticked variable, the backslash would apply
to its first character, which is almost certainly not what the user wanted.

Report an error in this case instead.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lexer-subst: make it possible to use on non-zero terminated strings

Instead of expecting a zero terminated input, allow the caller to pass
an explicit length parameter.

If length is -1, we assume input is zero-terminated.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-parser: fix error reporting in case yylloc is zero-sized

When pinpointing an error condition, a line of carets are drawn at the
syntax error position. However in some cases, the yylloc value contains
a zero-sized cell (e.g. first_column==last_column), in that case no
carets were drawn. Fix this by always printing at least one caret.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lex: change number parsing rule not to raise YY_FATAL_ERROR

YY_FATAL_ERRROR is too heavy, we should simply return the LL_ERROR token
so proper syntax error reporting is performed.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lex: break up YY_INPUT macro and handle substitution failures

This patch makes the YY_INPUT macro somewhat smaller by separating most
of the stuff into a function. I also added handling argument substitution
errors, which are reporting using YY_FATAL_ERROR.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lex: add alternative YY_FATAL_ERROR handling

Instead of calling exit() when a fatal error happens, return the LL_ERROR
token after printing the failure.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lex: remove trailing whitespace

This patch removes all trailing whitespace from cfg-lex.l

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lexer-subst: change invoke to accept a const pointer as input

Instead of changing the characters in-place in the buffer to terminate
strings, copy them to a temporary buffer so we can accept a const pointer.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lexer: don't take ownership of the buffer argument in cfg_lexer_include_buffer()

cfg_lexer_include_buffer() assumed ownership of the input buffer, e.g.
it took care of freeing it. This was a bit unintuitive and cumbersome to
use and this code wasn't performance critical anyway.

This patch changes the function to only get a borrowed reference and the
responsibility of freeing the buffer stays at the caller.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lexer: add backtick substitition to cfg_lexer_include_buffer

This patch enables backtick substitution in cfg_lexer_include_buffer()
calls, just as it is performed in cfg_lexer_include_file().

Another function, named
cfg_lexer_include_buffer_without_backtick_substitution() is also added,
which performs the previous function and is used when including block
generator results.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>