From: Date: Mon, 30 Jun 2008 17:48:50 +0000 (-0700) Subject: Fix for bad key on master X-Git-Tag: 0.22~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f5ab8b680b985876d432c051f9dc2c65a5698803;p=awesomized%2Flibmemcached Fix for bad key on master --- diff --git a/ChangeLog b/ChangeLog index d5c8734f..f170e0c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * Fix where master key was no being checked for "bad key" * Fixed bugs in stats output (thread output was wrong) * Clarified MEMCACHED_BAD_KEY_PROVIDED is return for bad prefix key. diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index 34fcb4ea..670b2550 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -134,7 +134,11 @@ memcached_return memcached_mget_by_key(memcached_st *ptr, } if (master_key && master_key_length) + { + if ((ptr->flags & MEM_VERIFY_KEY) && (memcachd_key_test((char **)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) + return MEMCACHED_BAD_KEY_PROVIDED; master_server_key= memcached_generate_hash(ptr, master_key, master_key_length); + } /* Here is where we pay for the non-block API. We need to remove any data sitting diff --git a/libmemcached/memcached_key.c b/libmemcached/memcached_key.c index ef1fe15f..4ea63919 100644 --- a/libmemcached/memcached_key.c +++ b/libmemcached/memcached_key.c @@ -8,7 +8,7 @@ memcached_return memcachd_key_test(char **keys, size_t *key_length, for (x= 0; x < number_of_keys; x++) { int y; - for (y= 0; y < key_length[x]; y++) + for (y= 0; y < *(key_length + x); y++) { if ((isgraph(keys[x][y])) == 0) return MEMCACHED_BAD_KEY_PROVIDED; diff --git a/tests/function.c b/tests/function.c index fb2f4bca..75c28490 100644 --- a/tests/function.c +++ b/tests/function.c @@ -566,7 +566,8 @@ test_return bad_key_test(memcached_st *memc) clone= memcached_clone(NULL, memc); assert(clone); - (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); string= memcached_get(clone, key, strlen(key), &string_length, &flags, &rc); @@ -575,13 +576,29 @@ test_return bad_key_test(memcached_st *memc) assert(!string); set= 0; - (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); string= memcached_get(clone, key, strlen(key), &string_length, &flags, &rc); assert(rc == MEMCACHED_NOTFOUND); assert(string_length == 0); assert(!string); + /* Test multi key for bad keys */ + { + char *keys[] = { "GoodKey", "Bad Key", "NotMine" }; + size_t key_lengths[] = { 7, 7, 7 }; + set= 1; + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_mget(clone, keys, &key_lengths, 3); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + + rc= memcached_mget_by_key(clone, "foo daddy", 9, keys, &key_lengths, 1); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + } + memcached_free(clone); return 0;