debuggers.hg

changeset 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 1434b8515233
children 548c29920f68
files tools/libxl/libxlu_cfg.c tools/libxl/libxlu_cfg_i.h tools/libxl/libxlu_cfg_l.c tools/libxl/libxlu_cfg_l.h tools/libxl/libxlu_cfg_l.l tools/libxl/libxlu_internal.h
line diff
     1.1 --- a/tools/libxl/libxlu_cfg.c	Tue Jan 11 19:30:16 2011 +0000
     1.2 +++ b/tools/libxl/libxlu_cfg.c	Tue Jan 11 19:31:41 2011 +0000
     1.3 @@ -24,6 +24,7 @@ static int ctx_prep(CfgParseContext *ctx
     1.4      ctx->cfg= cfg;
     1.5      ctx->err= 0;
     1.6      ctx->lexerrlineno= -1;
     1.7 +    ctx->likely_python= 0;
     1.8      ctx->scanner= 0;
     1.9      
    1.10      e= xlu__cfg_yylex_init_extra(ctx, &ctx->scanner);
    1.11 @@ -44,6 +45,14 @@ static void parse(CfgParseContext *ctx) 
    1.12      int r;
    1.13      r= xlu__cfg_yyparse(ctx);
    1.14      if (r) assert(ctx->err);
    1.15 +
    1.16 +    if (ctx->err && ctx->likely_python) {
    1.17 +        fputs(
    1.18 + "warning: Config file looks like it contains Python code.\n"
    1.19 + "warning:  Arbitrary Python is no longer supported.\n"
    1.20 + "warning:  See http://wiki.xen.org/xenwiki/PythonInXlConfig\n",
    1.21 +              ctx->cfg->report);
    1.22 +    }
    1.23  }
    1.24  
    1.25  int xlu_cfg_readfile(XLU_Config *cfg, const char *real_filename) {
     2.1 --- a/tools/libxl/libxlu_cfg_i.h	Tue Jan 11 19:30:16 2011 +0000
     2.2 +++ b/tools/libxl/libxlu_cfg_i.h	Tue Jan 11 19:31:41 2011 +0000
     2.3 @@ -16,6 +16,8 @@ char *xlu__cfgl_dequote(CfgParseContext*
     2.4  void xlu__cfg_yyerror(YYLTYPE *locp, CfgParseContext*, char const *msg);
     2.5  void xlu__cfgl_lexicalerror(CfgParseContext*, char const *msg);
     2.6  
     2.7 +void xlu__cfgl_likely_python(CfgParseContext *ctx);
     2.8 +
     2.9  
    2.10  
    2.11  /* Why oh why does bison not declare this in its autogenerated .h ? */
     3.1 --- a/tools/libxl/libxlu_cfg_l.c	Tue Jan 11 19:30:16 2011 +0000
     3.2 +++ b/tools/libxl/libxlu_cfg_l.c	Tue Jan 11 19:31:41 2011 +0000
     3.3 @@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char
     3.4  	*yy_cp = '\0'; \
     3.5  	yyg->yy_c_buf_p = yy_cp;
     3.6  
     3.7 -#define YY_NUM_RULES 15
     3.8 -#define YY_END_OF_BUFFER 16
     3.9 +#define YY_NUM_RULES 16
    3.10 +#define YY_END_OF_BUFFER 17
    3.11  /* This struct is not used in this scanner,
    3.12     but its presence is necessary. */
    3.13  struct yy_trans_info
    3.14 @@ -392,17 +392,17 @@ static yyconst flex_int32_t yy_ec[256] =
    3.15          1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
    3.16          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.17          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.18 -        1,    2,    1,    4,    5,    1,    1,    1,    6,    1,
    3.19 -        1,    1,    1,    7,    1,    1,    1,    8,    8,    8,
    3.20 -        8,    8,    8,    8,    8,    8,    8,    1,    9,    1,
    3.21 -       10,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.22 +        1,    2,    1,    4,    5,    1,    1,    1,    6,    7,
    3.23 +        7,    1,    7,    8,    7,    7,    1,    9,    9,    9,
    3.24 +        9,    9,    9,    9,    9,    9,    9,    7,   10,    1,
    3.25 +       11,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.26          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.27          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.28 -       11,   12,   13,    1,   14,    1,   15,   15,   15,   15,
    3.29 +       12,   13,   14,    1,   15,    1,   16,   16,   16,   16,
    3.30  
    3.31 -       15,   15,   16,   16,   16,   16,   16,   16,   16,   16,
    3.32 -       16,   16,   16,   16,   16,   16,   16,   16,   16,   15,
    3.33 -       16,   16,    1,    1,    1,    1,    1,    1,    1,    1,
    3.34 +       16,   16,   17,   17,   17,   17,   17,   17,   17,   17,
    3.35 +       17,   17,   17,   17,   17,   17,   17,   17,   17,   16,
    3.36 +       17,   17,    1,    1,    1,    1,    1,    1,    1,    1,
    3.37          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.38          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.39          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    3.40 @@ -419,54 +419,56 @@ static yyconst flex_int32_t yy_ec[256] =
    3.41          1,    1,    1,    1,    1
    3.42      } ;
    3.43  
    3.44 -static yyconst flex_int32_t yy_meta[17] =
    3.45 +static yyconst flex_int32_t yy_meta[18] =
    3.46      {   0,
    3.47 -        1,    2,    3,    1,    1,    1,    1,    4,    1,    1,
    3.48 -        1,    1,    1,    4,    4,    4
    3.49 +        1,    2,    3,    1,    1,    1,    1,    1,    4,    1,
    3.50 +        1,    1,    1,    1,    4,    4,    4
    3.51      } ;
    3.52  
    3.53 -static yyconst flex_int16_t yy_base[40] =
    3.54 +static yyconst flex_int16_t yy_base[41] =
    3.55      {   0,
    3.56 -        0,    0,   15,   17,   51,   54,   54,   54,   17,   45,
    3.57 -       16,   54,   15,   54,   54,   54,   54,    0,    0,   54,
    3.58 -       54,   20,   54,    0,   37,   54,   19,   54,    0,   18,
    3.59 -        0,    0,   54,   33,   37,   41,   45,   23,   49
    3.60 +        0,    0,   16,   18,   50,   56,   56,   56,   18,   39,
    3.61 +       17,   56,   56,   16,   56,   56,   56,   56,    0,    0,
    3.62 +       56,   56,   20,   56,    0,   26,   56,   21,   56,    0,
    3.63 +       19,    0,    0,   56,   35,   39,   43,   47,   22,   51
    3.64 +    } ;
    3.65 +
    3.66 +static yyconst flex_int16_t yy_def[41] =
    3.67 +    {   0,
    3.68 +       34,    1,   35,   35,   34,   34,   34,   34,   36,   37,
    3.69 +       38,   34,   34,   34,   34,   34,   34,   34,   39,   40,
    3.70 +       34,   34,   36,   34,   36,   37,   34,   38,   34,   38,
    3.71 +       34,   39,   40,    0,   34,   34,   34,   34,   34,   34
    3.72      } ;
    3.73  
    3.74 -static yyconst flex_int16_t yy_def[40] =
    3.75 -    {   0,
    3.76 -       33,    1,   34,   34,   33,   33,   33,   33,   35,   36,
    3.77 -       37,   33,   33,   33,   33,   33,   33,   38,   39,   33,
    3.78 -       33,   35,   33,   35,   36,   33,   37,   33,   37,   33,
    3.79 -       38,   39,    0,   33,   33,   33,   33,   33,   33
    3.80 -    } ;
    3.81 -
    3.82 -static yyconst flex_int16_t yy_nxt[71] =
    3.83 +static yyconst flex_int16_t yy_nxt[74] =
    3.84      {   0,
    3.85          6,    7,    8,    9,   10,   11,   12,   13,   14,   15,
    3.86 -       16,    6,   17,    6,   18,   18,   20,   21,   20,   21,
    3.87 -       23,   28,   30,   23,   28,   30,   31,   29,   24,   30,
    3.88 -       29,   24,   30,   19,   19,   19,   19,   22,   22,   26,
    3.89 -       22,   25,   25,   25,   25,   27,   27,   26,   27,   32,
    3.90 -       33,   33,   32,    5,   33,   33,   33,   33,   33,   33,
    3.91 -       33,   33,   33,   33,   33,   33,   33,   33,   33,   33
    3.92 +       16,   17,    6,   18,    6,   19,   19,   21,   22,   21,
    3.93 +       22,   24,   29,   24,   31,   32,   29,   31,   27,   30,
    3.94 +       25,   31,   25,   30,   31,   20,   20,   20,   20,   23,
    3.95 +       23,   27,   23,   26,   26,   26,   26,   28,   28,   34,
    3.96 +       28,   33,   34,   34,   33,    5,   34,   34,   34,   34,
    3.97 +       34,   34,   34,   34,   34,   34,   34,   34,   34,   34,
    3.98 +       34,   34,   34
    3.99      } ;
   3.100  
   3.101 -static yyconst flex_int16_t yy_chk[71] =
   3.102 +static yyconst flex_int16_t yy_chk[74] =
   3.103      {   0,
   3.104          1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
   3.105 -        1,    1,    1,    1,    1,    1,    3,    3,    4,    4,
   3.106 -        9,   11,   13,   22,   27,   30,   38,   11,    9,   13,
   3.107 -       27,   22,   30,   34,   34,   34,   34,   35,   35,   25,
   3.108 -       35,   36,   36,   36,   36,   37,   37,   10,   37,   39,
   3.109 -        5,    0,   39,   33,   33,   33,   33,   33,   33,   33,
   3.110 -       33,   33,   33,   33,   33,   33,   33,   33,   33,   33
   3.111 +        1,    1,    1,    1,    1,    1,    1,    3,    3,    4,
   3.112 +        4,    9,   11,   23,   14,   39,   28,   31,   26,   11,
   3.113 +        9,   14,   23,   28,   31,   35,   35,   35,   35,   36,
   3.114 +       36,   10,   36,   37,   37,   37,   37,   38,   38,    5,
   3.115 +       38,   40,    0,    0,   40,   34,   34,   34,   34,   34,
   3.116 +       34,   34,   34,   34,   34,   34,   34,   34,   34,   34,
   3.117 +       34,   34,   34
   3.118      } ;
   3.119  
   3.120  /* Table of booleans, true if rule could match eol. */
   3.121 -static yyconst flex_int32_t yy_rule_can_match_eol[16] =
   3.122 +static yyconst flex_int32_t yy_rule_can_match_eol[17] =
   3.123      {   0,
   3.124 -0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,     };
   3.125 +0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,     };
   3.126  
   3.127  /* The intent behind this definition is that it'll catch
   3.128   * any uses of REJECT which flex missed.
   3.129 @@ -496,7 +498,7 @@ int xlu__cfg_yyget_column(yyscan_t yysca
   3.130  void xlu__cfg_yyset_column(int  column_no, yyscan_t yyscanner);
   3.131  
   3.132  
   3.133 -#line 500 "libxlu_cfg_l.c"
   3.134 +#line 502 "libxlu_cfg_l.c"
   3.135  
   3.136  #define INITIAL 0
   3.137  #define lexerr 1
   3.138 @@ -744,7 +746,7 @@ YY_DECL
   3.139  #line 37 "libxlu_cfg_l.l"
   3.140  
   3.141  
   3.142 -#line 748 "libxlu_cfg_l.c"
   3.143 +#line 750 "libxlu_cfg_l.c"
   3.144  
   3.145      yylval = yylval_param;
   3.146  
   3.147 @@ -2094,4 +2096,4 @@ void xlu__cfg_yyfree (void * ptr , yysca
   3.148  
   3.149  #define YYTABLES_NAME "yytables"
   3.150  
   3.151 -#line 82 "libxlu_cfg_l.l"
   3.152 +#line 88 "libxlu_cfg_l.l"
     4.1 --- a/tools/libxl/libxlu_cfg_l.h	Tue Jan 11 19:30:16 2011 +0000
     4.2 +++ b/tools/libxl/libxlu_cfg_l.h	Tue Jan 11 19:31:41 2011 +0000
     4.3 @@ -350,7 +350,7 @@ extern int xlu__cfg_yylex \
     4.4  #undef YY_DECL
     4.5  #endif
     4.6  
     4.7 -#line 82 "libxlu_cfg_l.l"
     4.8 +#line 88 "libxlu_cfg_l.l"
     4.9  
    4.10  #line 356 "libxlu_cfg_l.h"
    4.11  #undef xlu__cfg_yyIN_HEADER
     5.1 --- a/tools/libxl/libxlu_cfg_l.l	Tue Jan 11 19:30:16 2011 +0000
     5.2 +++ b/tools/libxl/libxlu_cfg_l.l	Tue Jan 11 19:31:41 2011 +0000
     5.3 @@ -64,6 +64,12 @@ void xlu__cfg_yyset_column(int  column_n
     5.4                            GOT(STRING);
     5.5                          }
     5.6  
     5.7 +[+-.():]                {
     5.8 +                          ctx->likely_python= 1;
     5.9 +                          BEGIN(lexerr);
    5.10 +                          yymore();
    5.11 +                        }
    5.12 +
    5.13  .                       {
    5.14                            BEGIN(lexerr);
    5.15                            yymore();
     6.1 --- a/tools/libxl/libxlu_internal.h	Tue Jan 11 19:30:16 2011 +0000
     6.2 +++ b/tools/libxl/libxlu_internal.h	Tue Jan 11 19:31:41 2011 +0000
     6.3 @@ -41,7 +41,7 @@ struct XLU_Config {
     6.4  
     6.5  typedef struct {
     6.6      XLU_Config *cfg;
     6.7 -    int err, lexerrlineno;
     6.8 +    int err, lexerrlineno, likely_python;
     6.9      void *scanner;
    6.10  } CfgParseContext;
    6.11