From: Brian Aker Date: Wed, 1 Jul 2009 16:18:18 +0000 (-0700) Subject: Work inspired by matt knox X-Git-Tag: 0.31~8 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=75c771a6f6e51c18775e4db8045ef3b6dead8779;p=m6w6%2Flibmemcached Work inspired by matt knox --- diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index 5deb5c75..e3249c06 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -170,12 +170,15 @@ uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_ if (ptr->flags & MEM_HASH_WITH_PREFIX_KEY) { - int temp_len= ptr->prefix_key_length + key_length; - char *temp= (char *)malloc(temp_len); + size_t temp_length= ptr->prefix_key_length + key_length; + char temp[temp_length]; + + if (temp_length > MEMCACHED_MAX_KEY -1) + return 0; + strncpy(temp, ptr->prefix_key, ptr->prefix_key_length); strncpy(temp + ptr->prefix_key_length, key, key_length); - hash= generate_hash(ptr, temp, temp_len); - free(temp); + hash= generate_hash(ptr, temp, temp_length); } else {