From: Date: Sun, 27 Jul 2008 11:00:37 +0000 (-0700) Subject: Fix for zero length bad key fix. X-Git-Tag: 0.23~22 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ed1af1f5b70f7da90f5e8d255df134a8ccf3f526;p=awesomized%2Flibmemcached Fix for zero length bad key fix. --- diff --git a/ChangeLog b/ChangeLog index 47c4f76c..f047278e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Solaris 64bit fix. * Support for weighted Ketama from Yin Chen. * Fix for Chinese + * Fix for 0 length key to trigger bad key. 0.22 Mon Jul 14 09:24:11 PDT 2008 * Fix where master key was no being checked for "bad key" diff --git a/libmemcached/memcached_key.c b/libmemcached/memcached_key.c index 4ea63919..7513592b 100644 --- a/libmemcached/memcached_key.c +++ b/libmemcached/memcached_key.c @@ -8,6 +8,10 @@ memcached_return memcachd_key_test(char **keys, size_t *key_length, for (x= 0; x < number_of_keys; x++) { int y; + + if (*(key_length + x) == 0) + return MEMCACHED_BAD_KEY_PROVIDED; + for (y= 0; y < *(key_length + x); y++) { if ((isgraph(keys[x][y])) == 0) diff --git a/tests/function.c b/tests/function.c index b0fc1fd8..0b2c15d4 100644 --- a/tests/function.c +++ b/tests/function.c @@ -630,6 +630,16 @@ test_return bad_key_test(memcached_st *memc) assert(rc == MEMCACHED_BAD_KEY_PROVIDED); } + /* Make sure zero length keys are marked as bad */ + set= 1; + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); + string= memcached_get(clone, key, 0, + &string_length, &flags, &rc); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + assert(string_length == 0); + assert(!string); + memcached_free(clone); return 0;