Skip to content
Browse files

Make sane variable names for cluster in memcached, check for max key …

…length.
  • Loading branch information...
1 parent 6d6b312 commit c272c4b531e92e6e41af5e1e5f4e06e2d5d0ae2c @jbuchbinder jbuchbinder committed Jan 23, 2013
Showing with 9 additions and 4 deletions.
  1. +8 −3 gmetad/rrd_helpers.c
  2. +1 −1 gmetad/rrd_helpers.h
View
11 gmetad/rrd_helpers.c
@@ -319,13 +319,18 @@ push_data_to_carbon( char *graphite_msg)
}
#ifdef WITH_MEMCACHED
+#define MEMCACHED_MAX_KEY_LENGTH 256
int
-write_data_to_memcached ( const char *source, const char *host, const char *metric,
+write_data_to_memcached ( const char *cluster, const char *host, const char *metric,
const char *sum, unsigned int process_time, unsigned int expiry )
{
time_t expiry_time;
- char s_path[256];
- sprintf(s_path, "%s/%s/%s", source, host, metric);
+ char s_path[MEMCACHED_MAX_KEY_LENGTH];
+ if (strlen(cluster) + strlen(host) + strlen(metric) + 2 > MEMCACHED_MAX_KEY_LENGTH) {
+ debug_msg("Cluster + host + metric + 2 > %d", MEMCACHED_MAX_KEY_LENGTH);
+ return EXIT_FAILURE;
+ }
+ sprintf(s_path, "%s/%s/%s", cluster, host, metric);
if (expiry != 0) {
expiry_time = time(NULL) + expiry;
View
2 gmetad/rrd_helpers.h
@@ -12,7 +12,7 @@ write_data_to_rrd ( const char *source, const char *host, const char *metric,
#ifdef WITH_MEMCACHED
int
-write_data_to_memcached ( const char *source, const char *host, const char *metric,
+write_data_to_memcached ( const char *cluster, const char *host, const char *metric,
const char *sum, unsigned int process_time, unsigned int expiry );
#endif /* WITH_MEMCACHED */

0 comments on commit c272c4b

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