From c1a11fb8b65ec3bf255390a87cd3600b9b588b4b Mon Sep 17 00:00:00 2001 From: Steve Beattie Date: Fri, 14 Jan 2011 16:55:20 -0600 Subject: [PATCH] Merge from trunk revision 1572: This patch fixes the parser's lexer to not passthrough other invalid characters in variable declarations. It also adds testcases demonstrating the issue. Nominated-By: Steve Beattie --- parser/parser_lex.l | 5 +++++ parser/tst/simple_tests/vars/vars_bad_1.sd | 10 ++++++++++ parser/tst/simple_tests/vars/vars_bad_2.sd | 10 ++++++++++ parser/tst/simple_tests/vars/vars_bad_3.sd | 10 ++++++++++ .../simple_tests/vars/vars_bad_trailing_garbage_1.sd | 10 ++++++++++ 5 files changed, 45 insertions(+) create mode 100644 parser/tst/simple_tests/vars/vars_bad_1.sd create mode 100644 parser/tst/simple_tests/vars/vars_bad_2.sd create mode 100644 parser/tst/simple_tests/vars/vars_bad_3.sd create mode 100644 parser/tst/simple_tests/vars/vars_bad_trailing_garbage_1.sd diff --git a/parser/parser_lex.l b/parser/parser_lex.l index 4c3ef995e..9436f7ccc 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -390,6 +390,11 @@ LT_EQUAL <= current_lineno++; BEGIN(INITIAL); } + [^\n] { + DUMP_PREPROCESS; + /* Something we didn't expect */ + yyerror(_("Found unexpected character: '%s'"), yytext); + } } { diff --git a/parser/tst/simple_tests/vars/vars_bad_1.sd b/parser/tst/simple_tests/vars/vars_bad_1.sd new file mode 100644 index 000000000..beb466f2d --- /dev/null +++ b/parser/tst/simple_tests/vars/vars_bad_1.sd @@ -0,0 +1,10 @@ +#=DESCRIPTION trailing garbage should trigger an error +#=EXRESULT FAIL + +@{LIBVIRT} = "libvirt + +/does/not/exist { + + change_profile -> + @{LIBVIRT}-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*, +} diff --git a/parser/tst/simple_tests/vars/vars_bad_2.sd b/parser/tst/simple_tests/vars/vars_bad_2.sd new file mode 100644 index 000000000..17311623c --- /dev/null +++ b/parser/tst/simple_tests/vars/vars_bad_2.sd @@ -0,0 +1,10 @@ +#=DESCRIPTION garbage should trigger an error +#=EXRESULT FAIL + +@{LIBVIRT} = lib"virt + +/does/not/exist { + + change_profile -> + @{LIBVIRT}-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*, +} diff --git a/parser/tst/simple_tests/vars/vars_bad_3.sd b/parser/tst/simple_tests/vars/vars_bad_3.sd new file mode 100644 index 000000000..5a286f304 --- /dev/null +++ b/parser/tst/simple_tests/vars/vars_bad_3.sd @@ -0,0 +1,10 @@ +#=DESCRIPTION garbage should trigger an error +#=EXRESULT FAIL + +@{LIBVIRT} = lib!virt libfail + +/does/not/exist { + + change_profile -> + @{LIBVIRT}-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*, +} diff --git a/parser/tst/simple_tests/vars/vars_bad_trailing_garbage_1.sd b/parser/tst/simple_tests/vars/vars_bad_trailing_garbage_1.sd new file mode 100644 index 000000000..5dfb84a43 --- /dev/null +++ b/parser/tst/simple_tests/vars/vars_bad_trailing_garbage_1.sd @@ -0,0 +1,10 @@ +#=DESCRIPTION trailing garbage should trigger an error +#=EXRESULT FAIL + +@{LIBVIRT} = libvirt" + +/does/not/exist { + + change_profile -> + @{LIBVIRT}-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*, +}