From 12c09f44cb291b1ecc4074cb3a55775b375fa8b2 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Sun, 25 Aug 2013 14:16:27 +0200 Subject: [PATCH] THRIFT-667 Period should not be allowed in identifier names Patch: Jens Geyer --- compiler/cpp/src/main.cc | 12 ++++++++++++ compiler/cpp/src/main.h | 5 +++++ compiler/cpp/src/thrifty.yy | 11 +++++++++++ 3 files changed, 28 insertions(+) diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index da45ae75..f7514193 100755 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -805,6 +805,18 @@ void validate_const_rec(std::string name, t_type* type, t_const_value* value) { } } +/** + * Check simple identifier names + * It's easier to do it this way instead of rewriting the whole grammar etc. + */ +void validate_simple_identifier(const char* identifier) { + string name( identifier); + if( name.find(".") != string::npos) { + yyerror("Identifier %s can't have a dot.", identifier); + exit(1); + } +} + /** * Check the type of the parsed const information against its declared type */ diff --git a/compiler/cpp/src/main.h b/compiler/cpp/src/main.h index cb6d27a6..46ad8353 100644 --- a/compiler/cpp/src/main.h +++ b/compiler/cpp/src/main.h @@ -57,6 +57,11 @@ void pverbose(const char* fmt, ...); */ void failure(const char* fmt, ...); +/** + * Check simple identifier names + */ +void validate_simple_identifier(const char* identifier); + /** * Check constant types */ diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index 5b91a0a2..f5ab4a61 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -515,6 +515,7 @@ Typedef: tok_typedef FieldType tok_identifier TypeAnnotations { pdebug("TypeDef -> tok_typedef FieldType tok_identifier"); + validate_simple_identifier( $3); t_typedef *td = new t_typedef(g_program, $2, $3); $$ = td; if ($4 != NULL) { @@ -536,6 +537,7 @@ Enum: { pdebug("Enum -> tok_enum tok_identifier { EnumDefList }"); $$ = $4; + validate_simple_identifier( $2); $$->set_name($2); if ($6 != NULL) { $$->annotations_ = $6->annotations_; @@ -581,6 +583,7 @@ EnumDef: if ($4 > INT_MAX) { pwarning(1, "64-bit value supplied for enum %s.\n", $2); } + validate_simple_identifier( $2); $$ = new t_enum_value($2, $4); if ($1 != NULL) { $$->set_doc($1); @@ -594,6 +597,7 @@ EnumDef: CaptureDocText tok_identifier TypeAnnotations CommaOrSemicolonOptional { pdebug("EnumDef -> tok_identifier"); + validate_simple_identifier( $2); $$ = new t_enum_value($2); if ($1 != NULL) { $$->set_doc($1); @@ -608,6 +612,7 @@ Senum: tok_senum tok_identifier '{' SenumDefList '}' TypeAnnotations { pdebug("Senum -> tok_senum tok_identifier { SenumDefList }"); + validate_simple_identifier( $2); $$ = new t_typedef(g_program, $4, $2); if ($6 != NULL) { $$->annotations_ = $6->annotations_; @@ -641,6 +646,7 @@ Const: { pdebug("Const -> tok_const FieldType tok_identifier = ConstValue"); if (g_parse_mode == PROGRAM) { + validate_simple_identifier( $3); g_scope->resolve_const_value($5, $2); $$ = new t_const($2, $3, $5); validate_const_type($$); @@ -748,6 +754,7 @@ Struct: StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations { pdebug("Struct -> tok_struct tok_identifier { FieldList }"); + validate_simple_identifier( $2); $5->set_xsd_all($3); $5->set_union($1 == struct_is_union); $$ = $5; @@ -802,6 +809,7 @@ Xception: tok_xception tok_identifier '{' FieldList '}' TypeAnnotations { pdebug("Xception -> tok_xception tok_identifier { FieldList }"); + validate_simple_identifier( $2); $4->set_name($2); $4->set_xception(true); $$ = $4; @@ -815,6 +823,7 @@ Service: tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}' TypeAnnotations { pdebug("Service -> tok_service tok_identifier { FunctionList }"); + validate_simple_identifier( $2); $$ = $6; $$->set_name($2); $$->set_extends($3); @@ -868,6 +877,7 @@ FunctionList: Function: CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws TypeAnnotations CommaOrSemicolonOptional { + validate_simple_identifier( $4); $6->set_name(std::string($4) + "_args"); $$ = new t_function($3, $4, $6, $8, $2); if ($1 != NULL) { @@ -932,6 +942,7 @@ Field: exit(1); } } + validate_simple_identifier($5); $$ = new t_field($4, $5, $2.value); $$->set_req($3); if ($6 != NULL) { -- 2.17.1