From 46654a83342e4db851b7a5e5772ff4f11a98c3f5 Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Mon, 29 Sep 2008 13:27:24 +0200 Subject: [PATCH] stats_prefix_* should not assume that all keys are zero-terminated --- memcached.c | 12 ++++++------ stats.c | 16 ++++++++-------- stats.h | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/memcached.c b/memcached.c index c3debc12bb..5df0647003 100644 --- a/memcached.c +++ b/memcached.c @@ -1448,7 +1448,7 @@ static void process_bin_update(conn *c) { } if (settings.detail_enabled) { - stats_prefix_record_set(key); + stats_prefix_record_set(key, nkey); } it = item_alloc(key, nkey, req->message.body.flags, @@ -1510,7 +1510,7 @@ static void process_bin_append_prepend(conn *c) { } if (settings.detail_enabled) { - stats_prefix_record_set(key); + stats_prefix_record_set(key, nkey); } it = item_alloc(key, nkey, 0, 0, vlen+2); @@ -1583,7 +1583,7 @@ static void process_bin_delete(conn *c) { } if (settings.detail_enabled) { - stats_prefix_record_delete(key); + stats_prefix_record_delete(key, nkey); } it = item_get(key, nkey); @@ -2160,7 +2160,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, stats_get_cmds++; it = item_get(key, nkey); if (settings.detail_enabled) { - stats_prefix_record_get(key, NULL != it); + stats_prefix_record_get(key, nkey, NULL != it); } if (it) { if (i >= c->isize) { @@ -2338,7 +2338,7 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken } if (settings.detail_enabled) { - stats_prefix_record_set(key); + stats_prefix_record_set(key, nkey); } if (settings.managed) { @@ -2521,7 +2521,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken } if (settings.detail_enabled) { - stats_prefix_record_delete(key); + stats_prefix_record_delete(key, nkey); } it = item_get(key, nkey); diff --git a/stats.c b/stats.c index 3cc3c3e4c6..9373c65182 100644 --- a/stats.c +++ b/stats.c @@ -66,14 +66,14 @@ void stats_prefix_clear() { * in the list. */ /*@null@*/ -static PREFIX_STATS *stats_prefix_find(const char *key) { +static PREFIX_STATS *stats_prefix_find(const char *key, const size_t nkey) { PREFIX_STATS *pfs; uint32_t hashval; size_t length; assert(key != NULL); - for (length = 0; key[length] != '\0'; length++) + for (length = 0; key[length] != '\0' && length < nkey; length++) if (key[length] == settings.prefix_delimiter) break; @@ -113,11 +113,11 @@ static PREFIX_STATS *stats_prefix_find(const char *key) { /* * Records a "get" of a key. */ -void stats_prefix_record_get(const char *key, const bool is_hit) { +void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); - pfs = stats_prefix_find(key); + pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_gets++; if (is_hit) { @@ -130,11 +130,11 @@ void stats_prefix_record_get(const char *key, const bool is_hit) { /* * Records a "delete" of a key. */ -void stats_prefix_record_delete(const char *key) { +void stats_prefix_record_delete(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); - pfs = stats_prefix_find(key); + pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_deletes++; } @@ -144,11 +144,11 @@ void stats_prefix_record_delete(const char *key) { /* * Records a "set" of a key. */ -void stats_prefix_record_set(const char *key) { +void stats_prefix_record_set(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); - pfs = stats_prefix_find(key); + pfs = stats_prefix_find(key, nkey); if (NULL != pfs) { pfs->num_sets++; } diff --git a/stats.h b/stats.h index 56db428d37..4a27ae94d3 100644 --- a/stats.h +++ b/stats.h @@ -1,8 +1,8 @@ /* stats */ void stats_prefix_init(void); void stats_prefix_clear(void); -void stats_prefix_record_get(const char *key, const bool is_hit); -void stats_prefix_record_delete(const char *key); -void stats_prefix_record_set(const char *key); +void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit); +void stats_prefix_record_delete(const char *key, const size_t nkey); +void stats_prefix_record_set(const char *key, const size_t nkey); /*@null@*/ char *stats_prefix_dump(int *length);