From: Brian Aker Date: Fri, 18 Mar 2011 18:12:06 +0000 (-0700) Subject: Additional fixes/test. We will now limit the hostname when adding it into X-Git-Tag: 0.51~15^2~75^2~20 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3381db937d9af684deb762143bef0f1632a37dcd;p=m6w6%2Flibmemcached Additional fixes/test. We will now limit the hostname when adding it into memc so that we don't do any sort of overflow by accident. --- diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 3efc675f..c861a6d9 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -450,3 +450,20 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, return run_distribution(ptr); } + +memcached_return_t memcached_server_add_parsed(memcached_st *ptr, + const char *hostname, + size_t hostname_length, + in_port_t port, + uint32_t weight) +{ + char buffer[NI_MAXHOST]; + + memcpy(buffer, hostname, hostname_length); + buffer[hostname_length]= 0; + + return server_add(ptr, buffer, + port, + weight, + MEMCACHED_CONNECTION_TCP); +} diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index 4bba48a2..8ac4d14d 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -102,7 +102,7 @@ statement: expression: SERVER '=' server { - (void) memcached_server_add(parser->memc, $3.c_str, $3.port); + (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0); } | SERVERS '=' server_list { } @@ -119,11 +119,11 @@ expression: server_list: server { - (void) memcached_server_add(parser->memc, $1.c_str, $1.port); + (void) memcached_server_add_parsed(parser->memc, $1.c_str, $1.length, $1.port, 0); } | server_list ',' server { - (void) memcached_server_add(parser->memc, $3.c_str, $3.port); + (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0); } ; diff --git a/libmemcached/server.h b/libmemcached/server.h index 4248e143..aadd690f 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -96,6 +96,13 @@ LIBMEMCACHED_API memcached_return_t memcached_server_add(memcached_st *ptr, const char *hostname, in_port_t port); +LIBMEMCACHED_LOCAL + memcached_return_t memcached_server_add_parsed(memcached_st *ptr, + const char *hostname, + size_t hostname_length, + in_port_t port, + uint32_t weight); + LIBMEMCACHED_API memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, const char *hostname, diff --git a/tests/parser.cc b/tests/parser.cc index e7a4414f..823970ed 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -84,7 +84,7 @@ test_return_t servers_test(memcached_st *junk) scanner_string_st test_strings[]= { { STRING_WITH_LEN("--servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225") }, - { STRING_WITH_LEN("--servers=a.example.com:80,localhost:80,b.example.com") }, + { STRING_WITH_LEN("--servers=a.example.com:81,localhost:82,b.example.com") }, { STRING_WITH_LEN("--servers=localhost,localhost:80") }, { NULL, 0} }; @@ -98,7 +98,7 @@ test_return_t servers_test(memcached_st *junk) memcached_server_fn callbacks[1]; callbacks[0]= server_print_callback; - memcached_server_cursor(memc, callbacks, memc, 1); + memcached_server_cursor(memc, callbacks, NULL, 1); memcached_servers_reset(memc); }