summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ba7ad86)
raw | patch | inline | side by side (parent: ba7ad86)
author | Florian Forster <octo@collectd.org> | |
Wed, 23 Nov 2011 13:28:27 +0000 (14:28 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 21 Jan 2012 10:30:44 +0000 (11:30 +0100) |
Change-Id: I1f7403b2e82edd099f0168d0a0735cd18f8ce05a
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 6d7c96e4e8862784ba3b1f3a4737057bd8701688..3c92df21cf20c1354cbd0121a68475462dfc48ba 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
return (0);
} /* int plugin_dispatch_values */
+int plugin_dispatch_values_secure (const value_list_t *vl)
+{
+ value_list_t vl_copy;
+ int status;
+
+ if (vl == NULL)
+ return EINVAL;
+
+ memcpy (&vl_copy, vl, sizeof (vl_copy));
+
+ /* Write callbacks must not change the values and meta pointers, so we can
+ * savely skip copying those and make this more efficient. */
+ if ((pre_cache_chain == NULL) && (post_cache_chain == NULL))
+ return (plugin_dispatch_values (&vl_copy));
+
+ /* Set pointers to NULL, just to be on the save side. */
+ vl_copy.values = NULL;
+ vl_copy.meta = NULL;
+
+ vl_copy.values = malloc (sizeof (*vl_copy.values) * vl->values_len);
+ if (vl_copy.values == NULL)
+ {
+ ERROR ("plugin_dispatch_values_secure: malloc failed.");
+ return (ENOMEM);
+ }
+ memcpy (vl_copy.values, vl->values, sizeof (*vl_copy.values) * vl->values_len);
+
+ if (vl->meta != NULL)
+ {
+ vl_copy.meta = meta_data_clone (vl->meta);
+ if (vl_copy.meta == NULL)
+ {
+ ERROR ("plugin_dispatch_values_secure: meta_data_clone failed.");
+ free (vl_copy.values);
+ return (ENOMEM);
+ }
+ } /* if (vl->meta) */
+
+ status = plugin_dispatch_values (&vl_copy);
+
+ meta_data_destroy (vl_copy.meta);
+ free (vl_copy.values);
+
+ return (status);
+} /* int plugin_dispatch_values_secure */
+
int plugin_dispatch_notification (const notification_t *notif)
{
llentry_t *le;
diff --git a/src/plugin.h b/src/plugin.h
index 3f94dbc89cc07ba10168aa84e7923f6e3eb6ac69..0b34ab1df146420e7a6a0a525fabbd7060a669c0 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
#define PLUGIN_H
/**
* collectd - src/plugin.h
- * Copyright (C) 2005-2008 Florian octo Forster
+ * Copyright (C) 2005-2011 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* function.
*/
int plugin_dispatch_values (value_list_t *vl);
+int plugin_dispatch_values_secure (const value_list_t *vl);
int plugin_dispatch_notification (const notification_t *notif);