From df37c661a4f75b030ad67a79e496f85299f600be Mon Sep 17 00:00:00 2001 From: Don Neufeld Date: Thu, 8 Mar 2012 17:27:59 -0800 Subject: [PATCH 1/2] Fixed wg_copy_escape_part writing an escape_char when it encounters the null terminator --- src/write_graphite.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/write_graphite.c b/src/write_graphite.c index 6b16bec..2cb1041 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -351,22 +351,25 @@ static void wg_copy_escape_part (char *dst, const char *src, size_t dst_len, { size_t i; - memset (dst, 0, dst_len); - if (src == NULL) + { + dst[0] = 0; return; + } for (i = 0; i < dst_len; i++) { - if ((src[i] == '.') + if (src[i] == 0) + { + dst[i] = '\0'; + break; + } + else if ((src[i] == '.') || isspace ((int) src[i]) || iscntrl ((int) src[i])) dst[i] = escape_char; else dst[i] = src[i]; - - if (src[i] == 0) - break; } } From 414f4e358f6915e5971dbb00a013e6154ad8cb5c Mon Sep 17 00:00:00 2001 From: Don Neufeld Date: Thu, 8 Mar 2012 18:48:58 -0800 Subject: [PATCH 2/2] Fixed wg_format_name printing garbage into string when ds_name is NULL, which this function receives from several plugins: df, uptime, memory --- src/write_graphite.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/write_graphite.c b/src/write_graphite.c index 2cb1041..68d264e 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -390,7 +390,6 @@ static int wg_format_name (char *ret, int ret_len, assert (hostname != NULL); assert (plugin != NULL); assert (type != NULL); - assert (ds_name != NULL); if (prefix == NULL) prefix = ""; @@ -413,34 +412,44 @@ static int wg_format_name (char *ret, int ret_len, { if (n_type_instance[0] == '\0') { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s", - prefix, n_hostname, postfix, n_plugin, n_type, ds_name); + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s", + prefix, n_hostname, postfix, n_plugin, n_type); } else { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s", prefix, n_hostname, postfix, n_plugin, n_type, - n_type_instance, ds_name); + n_type_instance); } } else { if (n_type_instance[0] == '\0') { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s", prefix, n_hostname, postfix, n_plugin, - n_plugin_instance, n_type, ds_name); + n_plugin_instance, n_type); } else { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s", prefix, n_hostname, postfix, n_plugin, - n_plugin_instance, n_type, n_type_instance, ds_name); + n_plugin_instance, n_type, n_type_instance); } } if ((status < 1) || (status >= ret_len)) return (-1); + + if( ds_name ) + { + int ret_remaining = ret_len - status; + + status = ssnprintf( ret + status, ret_remaining, ".%s", ds_name ); + + if ((status < 1) || (status >= ret_remaining)) + return (-1); + } return (0); }