[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: config parser: print warning for apparent arbitrary python



# HG changeset patch
# User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
# Date 1294774301 0
# Node ID cb94dbe20f97ae5ff242d4c7fe1a4dc57ee63c23
# Parent  1434b85152335d25c6c54f0aa03028b4edad85c8
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@xxxxxxxxxxxxx>
---
 tools/libxl/libxlu_cfg.c      |    9 ++++
 tools/libxl/libxlu_cfg_i.h    |    2 
 tools/libxl/libxlu_cfg_l.c    |   88 +++++++++++++++++++++---------------------
 tools/libxl/libxlu_cfg_l.h    |    2 
 tools/libxl/libxlu_cfg_l.l    |    6 ++
 tools/libxl/libxlu_internal.h |    2 
 6 files changed, 64 insertions(+), 45 deletions(-)

diff -r 1434b8515233 -r cb94dbe20f97 tools/libxl/libxlu_cfg.c
--- a/tools/libxl/libxlu_cfg.c  Tue Jan 11 19:30:16 2011 +0000
+++ b/tools/libxl/libxlu_cfg.c  Tue Jan 11 19:31:41 2011 +0000
@@ -24,6 +24,7 @@ static int ctx_prep(CfgParseContext *ctx
     ctx->cfg= cfg;
     ctx->err= 0;
     ctx->lexerrlineno= -1;
+    ctx->likely_python= 0;
     ctx->scanner= 0;
     
     e= xlu__cfg_yylex_init_extra(ctx, &ctx->scanner);
@@ -44,6 +45,14 @@ static void parse(CfgParseContext *ctx) 
     int r;
     r= xlu__cfg_yyparse(ctx);
     if (r) assert(ctx->err);
+
+    if (ctx->err && ctx->likely_python) {
+        fputs(
+ "warning: Config file looks like it contains Python code.\n"
+ "warning:  Arbitrary Python is no longer supported.\n"
+ "warning:  See http://wiki.xen.org/xenwiki/PythonInXlConfig\n";,
+              ctx->cfg->report);
+    }
 }
 
 int xlu_cfg_readfile(XLU_Config *cfg, const char *real_filename) {
diff -r 1434b8515233 -r cb94dbe20f97 tools/libxl/libxlu_cfg_i.h
--- a/tools/libxl/libxlu_cfg_i.h        Tue Jan 11 19:30:16 2011 +0000
+++ b/tools/libxl/libxlu_cfg_i.h        Tue Jan 11 19:31:41 2011 +0000
@@ -16,6 +16,8 @@ void xlu__cfg_yyerror(YYLTYPE *locp, Cfg
 void xlu__cfg_yyerror(YYLTYPE *locp, CfgParseContext*, char const *msg);
 void xlu__cfgl_lexicalerror(CfgParseContext*, char const *msg);
 
+void xlu__cfgl_likely_python(CfgParseContext *ctx);
+
 
 
 /* Why oh why does bison not declare this in its autogenerated .h ? */
diff -r 1434b8515233 -r cb94dbe20f97 tools/libxl/libxlu_cfg_l.c
--- a/tools/libxl/libxlu_cfg_l.c        Tue Jan 11 19:30:16 2011 +0000
+++ b/tools/libxl/libxlu_cfg_l.c        Tue Jan 11 19:31:41 2011 +0000
@@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char
        *yy_cp = '\0'; \
        yyg->yy_c_buf_p = yy_cp;
 
-#define YY_NUM_RULES 15
-#define YY_END_OF_BUFFER 16
+#define YY_NUM_RULES 16
+#define YY_END_OF_BUFFER 17
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -392,17 +392,17 @@ static yyconst flex_int32_t yy_ec[256] =
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    1,    4,    5,    1,    1,    1,    6,    1,
-        1,    1,    1,    7,    1,    1,    1,    8,    8,    8,
-        8,    8,    8,    8,    8,    8,    8,    1,    9,    1,
-       10,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    2,    1,    4,    5,    1,    1,    1,    6,    7,
+        7,    1,    7,    8,    7,    7,    1,    9,    9,    9,
+        9,    9,    9,    9,    9,    9,    9,    7,   10,    1,
+       11,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-       11,   12,   13,    1,   14,    1,   15,   15,   15,   15,
-
-       15,   15,   16,   16,   16,   16,   16,   16,   16,   16,
-       16,   16,   16,   16,   16,   16,   16,   16,   16,   15,
-       16,   16,    1,    1,    1,    1,    1,    1,    1,    1,
+       12,   13,   14,    1,   15,    1,   16,   16,   16,   16,
+
+       16,   16,   17,   17,   17,   17,   17,   17,   17,   17,
+       17,   17,   17,   17,   17,   17,   17,   17,   17,   16,
+       17,   17,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -419,54 +419,56 @@ static yyconst flex_int32_t yy_ec[256] =
         1,    1,    1,    1,    1
     } ;
 
-static yyconst flex_int32_t yy_meta[17] =
+static yyconst flex_int32_t yy_meta[18] =
     {   0,
-        1,    2,    3,    1,    1,    1,    1,    4,    1,    1,
-        1,    1,    1,    4,    4,    4
+        1,    2,    3,    1,    1,    1,    1,    1,    4,    1,
+        1,    1,    1,    1,    4,    4,    4
     } ;
 
-static yyconst flex_int16_t yy_base[40] =
+static yyconst flex_int16_t yy_base[41] =
     {   0,
-        0,    0,   15,   17,   51,   54,   54,   54,   17,   45,
-       16,   54,   15,   54,   54,   54,   54,    0,    0,   54,
-       54,   20,   54,    0,   37,   54,   19,   54,    0,   18,
-        0,    0,   54,   33,   37,   41,   45,   23,   49
+        0,    0,   16,   18,   50,   56,   56,   56,   18,   39,
+       17,   56,   56,   16,   56,   56,   56,   56,    0,    0,
+       56,   56,   20,   56,    0,   26,   56,   21,   56,    0,
+       19,    0,    0,   56,   35,   39,   43,   47,   22,   51
     } ;
 
-static yyconst flex_int16_t yy_def[40] =
+static yyconst flex_int16_t yy_def[41] =
     {   0,
-       33,    1,   34,   34,   33,   33,   33,   33,   35,   36,
-       37,   33,   33,   33,   33,   33,   33,   38,   39,   33,
-       33,   35,   33,   35,   36,   33,   37,   33,   37,   33,
-       38,   39,    0,   33,   33,   33,   33,   33,   33
+       34,    1,   35,   35,   34,   34,   34,   34,   36,   37,
+       38,   34,   34,   34,   34,   34,   34,   34,   39,   40,
+       34,   34,   36,   34,   36,   37,   34,   38,   34,   38,
+       34,   39,   40,    0,   34,   34,   34,   34,   34,   34
     } ;
 
-static yyconst flex_int16_t yy_nxt[71] =
+static yyconst flex_int16_t yy_nxt[74] =
     {   0,
         6,    7,    8,    9,   10,   11,   12,   13,   14,   15,
-       16,    6,   17,    6,   18,   18,   20,   21,   20,   21,
-       23,   28,   30,   23,   28,   30,   31,   29,   24,   30,
-       29,   24,   30,   19,   19,   19,   19,   22,   22,   26,
-       22,   25,   25,   25,   25,   27,   27,   26,   27,   32,
-       33,   33,   32,    5,   33,   33,   33,   33,   33,   33,
-       33,   33,   33,   33,   33,   33,   33,   33,   33,   33
+       16,   17,    6,   18,    6,   19,   19,   21,   22,   21,
+       22,   24,   29,   24,   31,   32,   29,   31,   27,   30,
+       25,   31,   25,   30,   31,   20,   20,   20,   20,   23,
+       23,   27,   23,   26,   26,   26,   26,   28,   28,   34,
+       28,   33,   34,   34,   33,    5,   34,   34,   34,   34,
+       34,   34,   34,   34,   34,   34,   34,   34,   34,   34,
+       34,   34,   34
     } ;
 
-static yyconst flex_int16_t yy_chk[71] =
+static yyconst flex_int16_t yy_chk[74] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    3,    3,    4,    4,
-        9,   11,   13,   22,   27,   30,   38,   11,    9,   13,
-       27,   22,   30,   34,   34,   34,   34,   35,   35,   25,
-       35,   36,   36,   36,   36,   37,   37,   10,   37,   39,
-        5,    0,   39,   33,   33,   33,   33,   33,   33,   33,
-       33,   33,   33,   33,   33,   33,   33,   33,   33,   33
+        1,    1,    1,    1,    1,    1,    1,    3,    3,    4,
+        4,    9,   11,   23,   14,   39,   28,   31,   26,   11,
+        9,   14,   23,   28,   31,   35,   35,   35,   35,   36,
+       36,   10,   36,   37,   37,   37,   37,   38,   38,    5,
+       38,   40,    0,    0,   40,   34,   34,   34,   34,   34,
+       34,   34,   34,   34,   34,   34,   34,   34,   34,   34,
+       34,   34,   34
     } ;
 
 /* Table of booleans, true if rule could match eol. */
-static yyconst flex_int32_t yy_rule_can_match_eol[16] =
+static yyconst flex_int32_t yy_rule_can_match_eol[17] =
     {   0,
-0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,     };
+0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,     };
 
 /* The intent behind this definition is that it'll catch
  * any uses of REJECT which flex missed.
@@ -496,7 +498,7 @@ void xlu__cfg_yyset_column(int  column_n
 void xlu__cfg_yyset_column(int  column_no, yyscan_t yyscanner);
 
 
-#line 500 "libxlu_cfg_l.c"
+#line 502 "libxlu_cfg_l.c"
 
 #define INITIAL 0
 #define lexerr 1
@@ -744,7 +746,7 @@ YY_DECL
 #line 37 "libxlu_cfg_l.l"
 
 
-#line 748 "libxlu_cfg_l.c"
+#line 750 "libxlu_cfg_l.c"
 
     yylval = yylval_param;
 
@@ -2094,4 +2096,4 @@ void xlu__cfg_yyfree (void * ptr , yysca
 
 #define YYTABLES_NAME "yytables"
 
-#line 82 "libxlu_cfg_l.l"
+#line 88 "libxlu_cfg_l.l"
diff -r 1434b8515233 -r cb94dbe20f97 tools/libxl/libxlu_cfg_l.h
--- a/tools/libxl/libxlu_cfg_l.h        Tue Jan 11 19:30:16 2011 +0000
+++ b/tools/libxl/libxlu_cfg_l.h        Tue Jan 11 19:31:41 2011 +0000
@@ -350,7 +350,7 @@ extern int xlu__cfg_yylex \
 #undef YY_DECL
 #endif
 
-#line 82 "libxlu_cfg_l.l"
+#line 88 "libxlu_cfg_l.l"
 
 #line 356 "libxlu_cfg_l.h"
 #undef xlu__cfg_yyIN_HEADER
diff -r 1434b8515233 -r cb94dbe20f97 tools/libxl/libxlu_cfg_l.l
--- a/tools/libxl/libxlu_cfg_l.l        Tue Jan 11 19:30:16 2011 +0000
+++ b/tools/libxl/libxlu_cfg_l.l        Tue Jan 11 19:31:41 2011 +0000
@@ -64,6 +64,12 @@ void xlu__cfg_yyset_column(int  column_n
                           GOT(STRING);
                         }
 
+[+-.():]                {
+                          ctx->likely_python= 1;
+                          BEGIN(lexerr);
+                          yymore();
+                        }
+
 .                       {
                           BEGIN(lexerr);
                           yymore();
diff -r 1434b8515233 -r cb94dbe20f97 tools/libxl/libxlu_internal.h
--- a/tools/libxl/libxlu_internal.h     Tue Jan 11 19:30:16 2011 +0000
+++ b/tools/libxl/libxlu_internal.h     Tue Jan 11 19:31:41 2011 +0000
@@ -41,7 +41,7 @@ struct XLU_Config {
 
 typedef struct {
     XLU_Config *cfg;
-    int err, lexerrlineno;
+    int err, lexerrlineno, likely_python;
     void *scanner;
 } CfgParseContext;
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.