From 9868238c8bf26b9566f9f65ec6d9e398cf9b1fc6 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 10 Jun 2011 15:16:29 -0700 Subject: [PATCH] Fix conditional jump in error message creation. --- libmemcached/connect.cc | 16 +++++++++++----- libmemcached/error.cc | 8 ++++---- libmemcached/io.cc | 7 +++++++ libmemcached/options.cc | 3 ++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index c9e91020..1d45ded1 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -47,11 +47,11 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) fds[0].fd = ptr->fd; fds[0].events = POLLOUT; - int error; size_t loop_max= 5; while (--loop_max) // Should only loop on cases of ERESTART or EINTR { + int error; if (ptr->root->poll_timeout) { error= poll(fds, 1, ptr->root->connect_timeout); @@ -76,9 +76,7 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) } else { - ptr->cached_errno= errno; - - return MEMCACHED_ERRNO; + return memcached_set_errno(*ptr, err, MEMCACHED_AT); } } case 0: @@ -93,7 +91,15 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) #endif case EINTR: continue; - default: + + case EFAULT: + case ENOMEM: + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + + case EINVAL: + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid")); + + default: // This should not happen if (fds[0].revents & POLLERR) { int err; diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 7914a165..b5e947a4 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -89,12 +89,12 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t error->rc= rc; error->local_errno= local_errno; - if (str and local_errno) + if (str and str->size and local_errno) { error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s(%s), %.*s -> %s", memcached_strerror(&memc, rc), strerror(local_errno), - int(error->size), str->c_str, at); + memcached_string_printf(*str), at); } else if (local_errno) { @@ -102,11 +102,11 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t memcached_strerror(&memc, rc), strerror(local_errno), at); } - else if (str) + else if (str and str->size) { error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s, %.*s -> %s", memcached_strerror(&memc, rc), - int(error->size), str->c_str, at); + int(str->size), str->c_str, at); } else { diff --git a/libmemcached/io.cc b/libmemcached/io.cc index d2c3a03d..fb4b0022 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -118,6 +118,13 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, case EINTR: break; + case EFAULT: + case ENOMEM: + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + + case EINVAL: + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid")); + default: if (fds.revents & POLLERR) { diff --git a/libmemcached/options.cc b/libmemcached/options.cc index d8b44ff7..16f378e8 100644 --- a/libmemcached/options.cc +++ b/libmemcached/options.cc @@ -89,9 +89,10 @@ memcached_return_t libmemcached_check_configuration(const char *option_string, s return MEMCACHED_MEMORY_ALLOCATION_FAILURE; memcached_return_t rc= memcached_parse_configuration(memc_ptr, option_string, length); - if (memcached_failed(rc) && error_buffer && error_buffer_size) + if (memcached_failed(rc) and error_buffer and error_buffer_size) { strncpy(error_buffer, memcached_last_error_message(memc_ptr), error_buffer_size); + error_buffer[length -1]= 0; } bool has_filename= memcached_behavior_get(memc_ptr, MEMCACHED_BEHAVIOR_LOAD_FROM_FILE); -- 2.30.2