debuggers.hg

view tools/libxl/libxlu_cfg_l.l @ 22781:cb94dbe20f97

libxl: config parser: print warning for apparent arbitrary python

The characters - + . ( ) : are not legal in xl config files but are
valid Python and use of at least one of them is almost essential for
writing arbitrary Python in the config file.

So if we see one of these during lexing, note it, and then after the
parse is complete if it failed we print a special extra warning.

Currently this warning refers to the nonexistent wiki page
http://wiki.xen.org/xenwiki/PythonInXlConfig
which will have to be written (and/or given a better name) before the
actual 4.1 release.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Jackson <Ian.Jackson@eu.citrix.com>
date Tue Jan 11 19:31:41 2011 +0000 (2011-01-11)
parents e5a9221bdd3f
children
line source
1 /* -*- fundamental -*- */
3 %{
4 #include "libxlu_cfg_i.h"
6 #define ctx ((CfgParseContext*)yyextra)
7 #define YY_NO_INPUT
9 #define GOT(x) do{ \
10 yylloc->first_line= yylineno; \
11 return (x); \
12 }while(0)
14 /* Some versions of flex have a bug (Fedora bugzilla 612465) which causes
15 * it to fail to declare these functions, which it defines. So declare
16 * them ourselves. Hopefully we won't have to simultaneously support
17 * a flex version which declares these differently somehow. */
18 int xlu__cfg_yyget_column(yyscan_t yyscanner);
19 void xlu__cfg_yyset_column(int column_no, yyscan_t yyscanner);
21 %}
23 %option warn
24 %option nodefault
25 %option batch
26 %option 8bit
27 %option yylineno
28 %option noyywrap
29 %option bison-bridge
30 %option bison-locations
31 %option reentrant
32 %option prefix="xlu__cfg_yy"
33 %option nounput
35 %x lexerr
37 %%
39 [a-z][_0-9a-z]* {
40 yylval->string= xlu__cfgl_strdup(ctx,yytext);
41 GOT(IDENT);
42 }
43 [0-9][0-9a-fx]* {
44 yylval->string= xlu__cfgl_strdup(ctx,yytext);
45 GOT(NUMBER);
46 }
48 [ \t]
50 , { GOT(','); }
51 \[ { GOT('['); }
52 \] { GOT(']'); }
53 \= { GOT('='); }
54 \; { GOT(';'); }
56 \n|\#.*\n { yylloc->first_line= yylineno-1; return NEWLINE; }
58 \'([^\'\\\n]|\\.)*\' {
59 yylval->string= xlu__cfgl_dequote(ctx,yytext);
60 GOT(STRING);
61 }
62 \"([^\"\\\n]|\\.)*\" {
63 yylval->string= xlu__cfgl_dequote(ctx,yytext);
64 GOT(STRING);
65 }
67 [+-.():] {
68 ctx->likely_python= 1;
69 BEGIN(lexerr);
70 yymore();
71 }
73 . {
74 BEGIN(lexerr);
75 yymore();
76 }
78 <lexerr>[^ \t\n]*|[ \t] {
79 xlu__cfgl_lexicalerror(ctx,"lexical error");
80 BEGIN(0);
81 }
83 <lexerr>\n {
84 xlu__cfgl_lexicalerror(ctx,"lexical error");
85 BEGIN(0);
86 GOT(NEWLINE);
87 }