From: Brian Aker Date: Wed, 23 Mar 2011 21:14:03 +0000 (-0700) Subject: Fix problem where hostname would end up with trailing . and be accepted as X-Git-Tag: 0.51~15^2~75^2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d9752c25d2f723d27e355d0c7090b65b0445c4a4;p=awesomized%2Flibmemcached Fix problem where hostname would end up with trailing . and be accepted as legit hostname. --- diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index bff5b28d..dd19ef8b 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -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 IPADDRESS_WITH_PORT %token STRING %token QUOTED_STRING +%token FILE_PATH %type server %type 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); diff --git a/libmemcached/options/scanner.l b/libmemcached/options/scanner.l index a3f91cb9..124900cf 100644 --- a/libmemcached/options/scanner.l +++ b/libmemcached/options/scanner.l @@ -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; diff --git a/tests/parser.cc b/tests/parser.cc index 4e0e23ff..968dd0c7 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -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} };