Additional fixes/test. We will now limit the hostname when adding it into
authorBrian Aker <brian@tangent.org>
Fri, 18 Mar 2011 18:12:06 +0000 (11:12 -0700)
committerBrian Aker <brian@tangent.org>
Fri, 18 Mar 2011 18:12:06 +0000 (11:12 -0700)
memc so that we don't do any sort of overflow by accident.

libmemcached/hosts.c
libmemcached/options/parser.yy
libmemcached/server.h
tests/parser.cc

index 3efc675f094fbb517491b082373be2e1a98c1d04..c861a6d9361ede3ff48c7aa5bc3cfccaaa321f9c 100644 (file)
@@ -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);
+}
index 4bba48a22aa5121bd4b407cea8fc56494109f748..8ac4d14d049dbddd9d82f781cab08e3b4b95f9b6 100644 (file)
@@ -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);
           }
         ;
 
index 4248e143f7c47e68d0a3c6c82d0a83b2e15458a9..aadd690fe0714e1b72e77b1081c4827ed074ca46 100644 (file)
@@ -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,
index e7a4414fdce53af07d554e16227bd9fc94dcb45d..823970ede167514716512c446e309082febaa4e4 100644 (file)
@@ -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);
   }