diff options
author | Dustin Sallings <dustin@spy.net> | 2009-04-02 11:42:19 -0700 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-04-02 12:24:55 -0700 |
commit | a4106cf31d24a4c200fbfc50660f24dcf903e08f (patch) | |
tree | 8d5f02513888154a0316d8a6cafd2ca9a7193a14 | |
parent | 17df5c0e055e0de94feecab1eb89a79ab6836628 (diff) | |
download | memcached-a4106cf31d24a4c200fbfc50660f24dcf903e08f.tar.gz |
Assert we're not overrunning a buffer in prefix stat creation.
-rw-r--r-- | stats.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -162,7 +162,7 @@ char *stats_prefix_dump(int *length) { PREFIX_STATS *pfs; char *buf; int i, pos; - size_t size; + size_t size = 0, written = 0, total_written = 0; /* * Figure out how big the buffer needs to be. This is the sum of the @@ -185,9 +185,12 @@ char *stats_prefix_dump(int *length) { pos = 0; for (i = 0; i < PREFIX_HASH_SIZE; i++) { for (pfs = prefix_stats[i]; NULL != pfs; pfs = pfs->next) { - pos += snprintf(buf + pos, size-pos, format, + written = snprintf(buf + pos, size-pos, format, pfs->prefix, pfs->num_gets, pfs->num_hits, pfs->num_sets, pfs->num_deletes); + pos += written; + total_written += written; + assert(total_written < size); } } |