Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

stats_prefix_* should not assume that all keys are zero-terminated

  • Loading branch information...
commit 46654a83342e4db851b7a5e5772ff4f11a98c3f5 1 parent b2e7e90
Trond Norbye authored dustin committed
Showing with 17 additions and 17 deletions.
  1. +6 −6 memcached.c
  2. +8 −8 stats.c
  3. +3 −3 stats.h
View
12 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);
View
16 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++;
}
View
6 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);

0 comments on commit 46654a8

Please sign in to comment.
Something went wrong with that request. Please try again.