diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2018-06-04 09:59:21 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2018-06-04 09:59:21 +0200 |
commit | 51a71ee15c1bcf0e82f363a16898f571e211f9c3 (patch) | |
tree | 2a03e117d072c55cfe2863d26b73e64d933e7ad8 /src/libstrongswan/settings/settings_lexer.l | |
parent | 7793611ee71b576dd9c66dee327349fa64e38740 (diff) | |
download | vyos-strongswan-51a71ee15c1bcf0e82f363a16898f571e211f9c3.tar.gz vyos-strongswan-51a71ee15c1bcf0e82f363a16898f571e211f9c3.zip |
New upstream version 5.6.3
Diffstat (limited to 'src/libstrongswan/settings/settings_lexer.l')
-rw-r--r-- | src/libstrongswan/settings/settings_lexer.l | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/src/libstrongswan/settings/settings_lexer.l b/src/libstrongswan/settings/settings_lexer.l index ce9d4eedc..fa1ecac10 100644 --- a/src/libstrongswan/settings/settings_lexer.l +++ b/src/libstrongswan/settings/settings_lexer.l @@ -1,7 +1,7 @@ %{ /* * Copyright (C) 2014 Tobias Brunner - * Hochschule fuer Technik Rapperswil + * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -49,6 +49,8 @@ static void include_files(parser_helper_t *ctx); /* type of our extra data */ %option extra-type="parser_helper_t*" +/* state used to scan values */ +%x val /* state used to scan include file patterns */ %x inc /* state used to scan quoted strings */ @@ -56,13 +58,17 @@ static void include_files(parser_helper_t *ctx); %% -[\t ]*#[^\n]* /* eat comments */ -[\t ]+ /* eat whitespace */ +[\t ]*#[^\r\n]* /* eat comments */ +[\t\r ]+ /* eat whitespace */ \n|#.*\n return NEWLINE; /* also eats comments at the end of a line */ "{" | -"}" | -"=" return yytext[0]; +"}" return yytext[0]; + +"=" { + yy_push_state(val, yyscanner); + return yytext[0]; +} "include"[\t ]+/[^=] { yyextra->string_init(yyextra); @@ -70,16 +76,53 @@ static void include_files(parser_helper_t *ctx); } "\"" { - yyextra->string_init(yyextra); - yy_push_state(str, yyscanner); + PARSER_DBG1(yyextra, "unexpected string detected"); + return STRING_ERROR; } -[^#{}="\n\t ]+ { +[^#{}="\r\n\t ]+ { yylval->s = strdup(yytext); return NAME; } +<val>{ + \r /* just ignore these */ + [\t ]+ + <<EOF>> | + [#}\n] { + if (*yytext) + { + switch (yytext[0]) + { + case '\n': + /* put the newline back to fix the line numbers */ + unput('\n'); + yy_set_bol(0); + break; + case '#': + case '}': + /* these are parsed outside of this start condition */ + unput(yytext[0]); + break; + } + } + yy_pop_state(yyscanner); + } + + "\"" { + yyextra->string_init(yyextra); + yy_push_state(str, yyscanner); + } + + /* same as above, but allow more characters */ + [^#}"\r\n\t ]+ { + yylval->s = strdup(yytext); + return NAME; + } +} + <inc>{ + \r /* just ignore these */ /* we allow all characters except #, } and spaces, they can be escaped */ <<EOF>> | [#}\n\t ] { @@ -111,12 +154,13 @@ static void include_files(parser_helper_t *ctx); \\["#} ] { yyextra->string_add(yyextra, yytext+1); } - [^"\\#}\n\t ]+ { + [^"\\#}\r\n\t ]+ { yyextra->string_add(yyextra, yytext); } } <str>{ + \r /* just ignore these */ "\"" | <<EOF>> | \\ { @@ -138,12 +182,13 @@ static void include_files(parser_helper_t *ctx); return STRING; } } + \\n yyextra->string_add(yyextra, "\n"); \\r yyextra->string_add(yyextra, "\r"); \\t yyextra->string_add(yyextra, "\t"); - \\\r?\n /* merge lines that end with EOL characters */ + \\\r?\n /* merge lines that end with escaped EOL characters */ \\. yyextra->string_add(yyextra, yytext+1); - [^\\"]+ { + [^\\\r"]+ { yyextra->string_add(yyextra, yytext); } } |