From: Brian Aker Date: Mon, 12 Nov 2007 08:44:43 +0000 (-0800) Subject: Fixed bug where zero length key was provided. X-Git-Tag: 0.10~19 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d3f7325607f4711aa6a0c5fa32c133afc67fa266;p=m6w6%2Flibmemcached Fixed bug where zero length key was provided. --- diff --git a/ChangeLog b/ChangeLog index 2b273ae5..136a58df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * different buffers are now kept for different connections to speed up async efforts * Modified increment/decrement functions to return uint64_t values + * Fixed bug in cases where zero length keys were provided 0.8 Mon Nov 5 10:40:41 PST 2007 * Adding support for CRC hash method diff --git a/include/memcached.h b/include/memcached.h index 6bf1e0be..bd056ade 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -60,6 +60,7 @@ typedef enum { MEMCACHED_ERRNO, MEMCACHED_FAIL_UNIX_SOCKET, MEMCACHED_NOT_SUPPORTED, + MEMCACHED_NO_KEY_PROVIDED, MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */ } memcached_return; diff --git a/lib/memcached_auto.c b/lib/memcached_auto.c index ad91f75b..d7e30e56 100644 --- a/lib/memcached_auto.c +++ b/lib/memcached_auto.c @@ -11,6 +11,9 @@ static memcached_return memcached_auto(memcached_st *ptr, char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; unsigned int server_key; + if (key_length == 0) + return MEMCACHED_NO_KEY_PROVIDED; + if (ptr->hosts == NULL || ptr->number_of_hosts == 0) return MEMCACHED_NO_SERVERS; diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index 0ed6092a..cedfa442 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -11,6 +11,9 @@ memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_lengt LIBMEMCACHED_MEMCACHED_DELETE_START(); + if (key_length == 0) + return MEMCACHED_NO_KEY_PROVIDED; + if (ptr->hosts == NULL || ptr->number_of_hosts == 0) return MEMCACHED_NO_SERVERS; diff --git a/lib/memcached_get.c b/lib/memcached_get.c index c0da409d..70d1b349 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -143,6 +143,9 @@ char *memcached_get(memcached_st *ptr, char *key, size_t key_length, memcached_string_st *result_buffer; LIBMEMCACHED_MEMCACHED_GET_START(); + if (key_length == 0) + return MEMCACHED_NO_KEY_PROVIDED; + if (ptr->hosts == NULL || ptr->number_of_hosts == 0) { *error= MEMCACHED_NO_SERVERS; diff --git a/lib/memcached_storage.c b/lib/memcached_storage.c index 70201489..099c78ac 100644 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@ -36,6 +36,9 @@ static memcached_return memcached_send(memcached_st *ptr, WATCHPOINT_ASSERT(value); WATCHPOINT_ASSERT(value_length); + if (key_length == 0) + return MEMCACHED_NO_KEY_PROVIDED; + /* Leaving this WATCHPOINT_ASSERT in since only a library fubar could blow this */ #ifdef NOT_DONE if (!(ptr->flags & MEM_NO_BLOCK) && ptr->write_buffer_offset != 0) diff --git a/lib/memcached_strerror.c b/lib/memcached_strerror.c index f541c17e..d2da6963 100644 --- a/lib/memcached_strerror.c +++ b/lib/memcached_strerror.c @@ -60,6 +60,8 @@ char *memcached_strerror(memcached_st *ptr, memcached_return rc) return "COULD NOT OPEN UNIX SOCKET"; case MEMCACHED_NOT_SUPPORTED: return "ACTION NOT SUPPORTED"; + case MEMCACHED_NO_KEY_PROVIDED: + return "A KEY LENGTH OF ZERO WAS PROVIDED"; case MEMCACHED_MAXIMUM_RETURN: return "Gibberish returned!"; default: