From: Marc Fournier Date: Wed, 10 Aug 2016 16:14:35 +0000 (+0200) Subject: src/daemon/common.c: avoid using private structs from X-Git-Tag: collectd-5.6.0~57^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3e211f8449bab9b9ef6f3b0e98817433101dc060;p=collectd.git src/daemon/common.c: avoid using private structs from --- diff --git a/src/daemon/common.c b/src/daemon/common.c index 76561916..a522759c 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -1677,23 +1677,42 @@ void strarray_free (char **array, size_t array_len) /* {{{ */ int check_capability (int capability) /* {{{ */ { #ifdef _LINUX_CAPABILITY_VERSION_3 - struct __user_cap_header_struct cap_header_data; - cap_user_header_t cap_header = &cap_header_data; - struct __user_cap_data_struct cap_data_data; - cap_user_data_t cap_data = &cap_data_data; + cap_user_header_t cap_header = calloc(sizeof (*cap_header), 1); + if (cap_header == NULL) + { + ERROR("check_capability: calloc failed"); + return (-1); + } + + cap_user_data_t cap_data = calloc(sizeof (*cap_data), 1); + if (cap_data == NULL) + { + ERROR("check_capability: calloc failed"); + return (-1); + } cap_header->pid = getpid(); cap_header->version = _LINUX_CAPABILITY_VERSION; if (capget(cap_header, cap_data) < 0) { ERROR("check_capability: capget failed"); + sfree(cap_header); + sfree(cap_data); return (-1); } if ((cap_data->effective & (1 << capability)) == 0) + { + sfree(cap_header); + sfree(cap_data); return (-1); + } else + { + sfree(cap_header); + sfree(cap_data); return (0); + } #else WARNING ("check_capability: unsupported capability implementation. " "Some plugin(s) may require elevated privileges to work properly.");