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:
@@ -207,14 +207,7 @@ valuepart:
|
|||||||
*/
|
*/
|
||||||
static void settings_parser_error(parser_helper_t *ctx, const char *s)
|
static void settings_parser_error(parser_helper_t *ctx, const char *s)
|
||||||
{
|
{
|
||||||
char *text = settings_parser_get_text(ctx->scanner);
|
PARSER_DBG1(ctx, "%s", s);
|
||||||
int len = settings_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, len, text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -212,14 +212,7 @@ value:
|
|||||||
*/
|
*/
|
||||||
static void conf_parser_error(parser_helper_t *ctx, const char *s)
|
static void conf_parser_error(parser_helper_t *ctx, const char *s)
|
||||||
{
|
{
|
||||||
char *text = conf_parser_get_text(ctx->scanner);
|
PARSER_DBG1(ctx, "%s", s);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user