From c6e2eddc3a033d9e382846f1771a9cb0bcc0cba7 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sat, 6 Oct 2012 22:07:09 -0400 Subject: [PATCH] Fix for lp:1062704 --- libmemcached/hosts.cc | 4 ++-- libmemcached/server.hpp | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 61c1b059..62b362ad 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -507,9 +507,9 @@ memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *pt } memcached_string_t _filename= { memcached_string_make_from_cstr(filename) }; - if (memcached_is_valid_servername(_filename) == false) + if (memcached_is_valid_filename(_filename) == false) { - memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid filename for socket provided")); + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid filename for socket provided")); } return server_add(ptr, _filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET); diff --git a/libmemcached/server.hpp b/libmemcached/server.hpp index 2719294f..351b34be 100644 --- a/libmemcached/server.hpp +++ b/libmemcached/server.hpp @@ -60,7 +60,12 @@ void __server_free(memcached_server_st *); static inline bool memcached_is_valid_servername(const memcached_string_t& arg) { - return arg.size < NI_MAXHOST; + return (arg.c_str != NULL or arg.size == 0) and arg.size < NI_MAXHOST; +} + +static inline bool memcached_is_valid_filename(const memcached_string_t& arg) +{ + return arg.c_str != NULL and arg.size > 0 and arg.size < NI_MAXHOST; } void memcached_instance_free(org::libmemcached::Instance *); -- 2.30.2