Fix: NULs don't work in string values

fixes #10234
This commit is contained in:
Gunnar Beutner 2015-09-29 07:09:35 +02:00
parent 8a2c7a055d
commit 6fb1b60c12
2 changed files with 60 additions and 55 deletions

View File

@ -71,8 +71,7 @@ do { \
yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine; yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine;
yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn; yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn;
std::string str = yyextra->m_LexBuffer.str(); yylval->text = new String(yyextra->m_LexBuffer.str());
yylval->text = strdup(str.c_str());
return T_STRING; return T_STRING;
} }
@ -139,8 +138,7 @@ do { \
yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine; yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine;
yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn; yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn;
std::string str = yyextra->m_LexBuffer.str(); yylval->text = new String(yyextra->m_LexBuffer.str());
yylval->text = strdup(str.c_str());
return T_STRING; return T_STRING;
} }
@ -210,9 +208,9 @@ in return T_IN;
\|\| return T_LOGICAL_OR; \|\| return T_LOGICAL_OR;
\{\{ return T_NULLARY_LAMBDA_BEGIN; \{\{ return T_NULLARY_LAMBDA_BEGIN;
\}\} return T_NULLARY_LAMBDA_END; \}\} return T_NULLARY_LAMBDA_END;
[a-zA-Z_][a-zA-Z0-9\_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; } [a-zA-Z_][a-zA-Z0-9\_]* { yylval->text = new String(yytext); return T_IDENTIFIER; }
@[a-zA-Z_][a-zA-Z0-9\_]* { yylval->text = strdup(yytext + 1); return T_IDENTIFIER; } @[a-zA-Z_][a-zA-Z0-9\_]* { yylval->text = new String(yytext + 1); return T_IDENTIFIER; }
\<[^ \>]*\> { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; } \<[^ \>]*\> { yytext[yyleng-1] = '\0'; yylval->text = new String(yytext + 1); return T_STRING_ANGLE; }
[0-9]+(\.[0-9]+)?ms { yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; } [0-9]+(\.[0-9]+)?ms { yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
[0-9]+(\.[0-9]+)?d { yylval->num = strtod(yytext, NULL) * 60 * 60 * 24; return T_NUMBER; } [0-9]+(\.[0-9]+)?d { yylval->num = strtod(yytext, NULL) * 60 * 60 * 24; return T_NUMBER; }
[0-9]+(\.[0-9]+)?h { yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; } [0-9]+(\.[0-9]+)?h { yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }

View File

@ -84,7 +84,7 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
%lex-param { void *scanner } %lex-param { void *scanner }
%union { %union {
char *text; String *text;
double num; double num;
bool boolean; bool boolean;
icinga::Expression *expr; icinga::Expression *expr;
@ -346,8 +346,8 @@ object:
bool abstract = $2; bool abstract = $2;
String type = $3; String type = *$3;
free($3); delete $3;
$6->MakeInline(); $6->MakeInline();
@ -407,8 +407,8 @@ identifier_items: /* empty */
identifier_items_inner: identifier identifier_items_inner: identifier
{ {
$$ = new std::vector<String>(); $$ = new std::vector<String>();
$$->push_back($1); $$->push_back(*$1);
free($1); delete $1;
} }
| identifier_items_inner ',' identifier | identifier_items_inner ',' identifier
{ {
@ -417,8 +417,8 @@ identifier_items_inner: identifier
else else
$$ = new std::vector<String>(); $$ = new std::vector<String>();
$$->push_back($3); $$->push_back(*$3);
free($3); delete $3;
} }
; ;
@ -443,32 +443,37 @@ lterm: T_LIBRARY rterm
} }
| T_INCLUDE T_STRING | T_INCLUDE T_STRING
{ {
$$ = context->HandleInclude($2, false, @$); $$ = context->HandleInclude(*$2, false, @$);
free($2); delete $2;
} }
| T_INCLUDE T_STRING_ANGLE | T_INCLUDE T_STRING_ANGLE
{ {
$$ = context->HandleInclude($2, true, @$); $$ = context->HandleInclude(*$2, true, @$);
free($2); delete $2;
} }
| T_INCLUDE_RECURSIVE T_STRING | T_INCLUDE_RECURSIVE T_STRING
{ {
$$ = context->HandleIncludeRecursive($2, "*.conf", @$); $$ = context->HandleIncludeRecursive(*$2, "*.conf", @$);
free($2); delete $2;
} }
| T_INCLUDE_RECURSIVE T_STRING ',' T_STRING | T_INCLUDE_RECURSIVE T_STRING ',' T_STRING
{ {
$$ = context->HandleIncludeRecursive($2, $4, @$); $$ = context->HandleIncludeRecursive(*$2, *$4, @$);
free($2); delete $2;
free($4); delete $4;
} }
| T_INCLUDE_ZONES T_STRING ',' T_STRING | T_INCLUDE_ZONES T_STRING ',' T_STRING
{ {
$$ = context->HandleIncludeZones($2, $4, "*.conf", @$); $$ = context->HandleIncludeZones(*$2, *$4, "*.conf", @$);
delete $2;
delete $4;
} }
| T_INCLUDE_ZONES T_STRING ',' T_STRING ',' T_STRING | T_INCLUDE_ZONES T_STRING ',' T_STRING ',' T_STRING
{ {
$$ = context->HandleIncludeZones($2, $4, $6, @$); $$ = context->HandleIncludeZones(*$2, *$4, *$6, @$);
delete $2;
delete $4;
delete $6;
} }
| T_IMPORT rterm | T_IMPORT rterm
{ {
@ -520,16 +525,16 @@ lterm: T_LIBRARY rterm
{ {
$9->MakeInline(); $9->MakeInline();
$$ = new ForExpression($3, $5, $7, $9, @$); $$ = new ForExpression(*$3, *$5, $7, $9, @$);
free($3); delete $3;
free($5); delete $5;
} }
| T_FOR '(' identifier T_IN rterm ')' rterm_scope_require_side_effect | T_FOR '(' identifier T_IN rterm ')' rterm_scope_require_side_effect
{ {
$7->MakeInline(); $7->MakeInline();
$$ = new ForExpression($3, "", $5, $7, @$); $$ = new ForExpression(*$3, "", $5, $7, @$);
free($3); delete $3;
} }
| T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope | T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope
{ {
@ -538,13 +543,13 @@ lterm: T_LIBRARY rterm
FunctionExpression *fexpr = new FunctionExpression(*$4, $6, $7, @$); FunctionExpression *fexpr = new FunctionExpression(*$4, $6, $7, @$);
delete $4; delete $4;
$$ = new SetExpression(MakeIndexer(ScopeThis, $2), OpSetLiteral, fexpr, @$); $$ = new SetExpression(MakeIndexer(ScopeThis, *$2), OpSetLiteral, fexpr, @$);
free($2); delete $2;
} }
| T_CONST T_IDENTIFIER T_SET rterm | T_CONST T_IDENTIFIER T_SET rterm
{ {
$$ = new SetExpression(MakeIndexer(ScopeGlobal, $2), OpSetLiteral, $4); $$ = new SetExpression(MakeIndexer(ScopeGlobal, *$2), OpSetLiteral, $4);
free($2); delete $2;
} }
| T_VAR rterm | T_VAR rterm
{ {
@ -692,8 +697,8 @@ rterm_side_effect: rterm '(' rterm_items ')'
aexpr->MakeInline(); aexpr->MakeInline();
std::vector<String> args; std::vector<String> args;
args.push_back($1); args.push_back(*$1);
free($1); delete $1;
$$ = new FunctionExpression(args, new std::map<String, Expression *>(), $3, @$); $$ = new FunctionExpression(args, new std::map<String, Expression *>(), $3, @$);
} }
@ -744,8 +749,8 @@ rterm_side_effect: rterm '(' rterm_items ')'
rterm_no_side_effect: T_STRING rterm_no_side_effect: T_STRING
{ {
$$ = MakeLiteral($1); $$ = MakeLiteral(*$1);
free($1); delete $1;
} }
| T_NUMBER | T_NUMBER
{ {
@ -761,8 +766,8 @@ rterm_no_side_effect: T_STRING
} }
| rterm '.' T_IDENTIFIER %dprec 2 | rterm '.' T_IDENTIFIER %dprec 2
{ {
$$ = new IndexerExpression($1, MakeLiteral($3), @$); $$ = new IndexerExpression($1, MakeLiteral(*$3), @$);
free($3); delete $3;
} }
| rterm '[' rterm ']' | rterm '[' rterm ']'
{ {
@ -770,8 +775,8 @@ rterm_no_side_effect: T_STRING
} }
| T_IDENTIFIER | T_IDENTIFIER
{ {
$$ = new VariableExpression($1, @1); $$ = new VariableExpression(*$1, @1);
free($1); delete $1;
} }
| '!' rterm | '!' rterm
{ {
@ -869,7 +874,7 @@ rterm: rterm_side_effect
target_type_specifier: /* empty */ target_type_specifier: /* empty */
{ {
$$ = strdup(""); $$ = new String();
} }
| T_TO identifier | T_TO identifier
{ {
@ -903,29 +908,31 @@ use_specifier_items: use_specifier_item
use_specifier_item: identifier use_specifier_item: identifier
{ {
$$ = new std::pair<String, Expression *>($1, new VariableExpression($1, @1)); $$ = new std::pair<String, Expression *>(*$1, new VariableExpression(*$1, @1));
delete $1;
} }
| identifier T_SET rterm | identifier T_SET rterm
{ {
$$ = new std::pair<String, Expression *>($1, $3); $$ = new std::pair<String, Expression *>(*$1, $3);
delete $1;
} }
; ;
apply_for_specifier: /* empty */ apply_for_specifier: /* empty */
| T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')' | T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')'
{ {
context->m_FKVar.top() = $3; context->m_FKVar.top() = *$3;
free($3); delete $3;
context->m_FVVar.top() = $5; context->m_FVVar.top() = *$5;
free($5); delete $5;
context->m_FTerm.top() = $7; context->m_FTerm.top() = $7;
} }
| T_FOR '(' identifier T_IN rterm ')' | T_FOR '(' identifier T_IN rterm ')'
{ {
context->m_FKVar.top() = $3; context->m_FKVar.top() = *$3;
free($3); delete $3;
context->m_FVVar.top() = ""; context->m_FVVar.top() = "";
@ -955,10 +962,10 @@ apply:
{ {
context->m_Apply.pop(); context->m_Apply.pop();
String type = $3; String type = *$3;
free($3); delete $3;
String target = $6; String target = *$6;
free($6); delete $6;
if (!ApplyRule::IsValidSourceType(type)) if (!ApplyRule::IsValidSourceType(type))
BOOST_THROW_EXCEPTION(ScriptError("'apply' cannot be used with type '" + type + "'", DebugInfoRange(@2, @3))); BOOST_THROW_EXCEPTION(ScriptError("'apply' cannot be used with type '" + type + "'", DebugInfoRange(@2, @3)));