Fix problem where hostname would end up with trailing . and be accepted as
authorBrian Aker <brian@tangent.org>
Wed, 23 Mar 2011 21:14:03 +0000 (14:14 -0700)
committerBrian Aker <brian@tangent.org>
Wed, 23 Mar 2011 21:14:03 +0000 (14:14 -0700)
legit hostname.

libmemcached/options/parser.yy
libmemcached/options/scanner.l
tests/parser.cc

index bff5b28df69bb7eaea48033927040399f2547b76..dd19ef8b52d3c98a58722b6fcaff2f3a3b24d645 100644 (file)
@@ -63,7 +63,14 @@ inline void parser_abort_func(Context *context, const char *error)
   std::string error_message;
   error_message+= context->begin;
   error_message+= " (";
-  error_message+= memcached_strerror(NULL, context->rc);
+  if (context->rc == MEMCACHED_PARSE_ERROR and error)
+  {
+    error_message+= error;
+  }
+  else
+  {
+    error_message+= memcached_strerror(NULL, context->rc);
+  }
   error_message+= ")";
 
   memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
@@ -159,6 +166,7 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne
 %token <string> IPADDRESS_WITH_PORT
 %token <string> STRING
 %token <string> QUOTED_STRING
+%token <string> FILE_PATH
 
 %type <server> server
 %type <string> string
@@ -170,8 +178,8 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne
 %%
 
 begin:
-          statement 
-        | statement ' ' statement
+          statement
+        | begin ' ' statement
         ;
 
 statement:
@@ -206,8 +214,9 @@ statement:
           {
             yydebug= 0;
           }
-        | INCLUDE string
+        | INCLUDE FILE_PATH
           {
+            std::cerr << "Got into INCLUDE" << std::endl;
             if ((context->rc= memcached_parse_configure_file(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
             {
               parser_abort(context, NULL);
index a3f91cb93babf7e16ff14455c066ccff4ed97913..124900cf75cd5f95576bccdcbf751b7b7ae92249 100644 (file)
@@ -159,7 +159,7 @@ static void get_lex_chars(char* buffer, int& result, int max_size, Context *cont
 "--PREFIX-KEY"                         { yyextra->begin= yytext; return PREFIX_KEY; }
 "--PREFIX_KEY"                         { yyextra->begin= yytext; return PREFIX_KEY; }
 
-INCLUDE           { yyextra->begin= yytext; return INCLUDE; }
+INCLUDE           { yyextra->begin= yytext; std::cerr << "Found INCLUDE" << std::endl; return INCLUDE; }
 RESET           { yyextra->begin= yytext; return RESET; }
 DEBUG           { yyextra->begin= yytext; return DEBUG; }
 SERVERS           { yyextra->begin= yytext; return SERVERS; }
@@ -194,7 +194,7 @@ JENKINS                     { return JENKINS; }
       return HOSTNAME_WITH_PORT;
     }
 
-[[:alnum:]]+"."[[:alpha:].]+ { 
+[[:alnum:]]+"."[[:alpha:].]+[[:alnum:]] { 
       yylval->string.c_str = yytext;
       yylval->string.length = yyleng;
       return HOSTNAME;
index 4e0e23ff6d1aa4d118748ccd73cb0a5747728037..968dd0c73203af04f54e8bd1ba45bb74bfbd7814 100644 (file)
@@ -174,6 +174,9 @@ scanner_variable_t bad_test_strings[]= {
   { ARRAY, make_scanner_string("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225"), scanner_string_null, NULL },
   { ARRAY, make_scanner_string("-- servers=a.example.com:81,localhost:82,b.example.com"), scanner_string_null, NULL },
   { ARRAY, make_scanner_string("--servers=localhost+80"), scanner_string_null, NULL},
+  { ARRAY, make_scanner_string("--servers=localhost.com."), scanner_string_null, NULL},
+  { ARRAY, make_scanner_string("--server=localhost.com."), scanner_string_null, NULL},
+  { ARRAY, make_scanner_string("--server=localhost.com.:80"), scanner_string_null, NULL},
   { NIL, scanner_string_null, scanner_string_null, NULL}
 };