X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fplugin.c;h=3c92df21cf20c1354cbd0121a68475462dfc48ba;hb=f4523a21e913449db2dbf79de3568b396b179ca1;hp=6d7c96e4e8862784ba3b1f3a4737057bd8701688;hpb=ba7ad8653e3c5d0eedbe65c4cd92359f5d2308e3;p=collectd.git diff --git a/src/plugin.c b/src/plugin.c index 6d7c96e4..3c92df21 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1523,6 +1523,52 @@ int plugin_dispatch_values (value_list_t *vl) 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;