Don't report current text in parser error messages

The values of `yytext` and `yyleng` might not be properly defined when
the error function is called (in particular if the lexer reached EOF).
While this might just cause non-printable characters in the output, it
could actually lead to a crash depending on where `yytext` points.

Closes strongswan/strongswan#346.
This commit is contained in:
Tobias Brunner
2021-05-11 10:08:58 +02:00
parent cf6a164108
commit c13a1c2829
2 changed files with 2 additions and 16 deletions
+1 -8
View File
@@ -212,14 +212,7 @@ value:
*/
static void conf_parser_error(parser_helper_t *ctx, const char *s)
{
char *text = conf_parser_get_text(ctx->scanner);
int len = conf_parser_get_leng(ctx->scanner);
if (len && text[len-1] == '\n')
{ /* cut off newline at the end to avoid muti-line log messages */
len--;
}
PARSER_DBG1(ctx, "%s [%.*s]", s, (int)len, text);
PARSER_DBG1(ctx, "%s", s);
}
/**