From a3899e593f6bae649def651f93473936c6fa64c2 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 23 Nov 2014 13:38:51 +0100 Subject: [PATCH] patches: Added bts770683_curl_init. Upstream fix for a segfault in plugins using libcurl caused by concurrent memory access. Thanks to Marc Fournier for reporting this. Closes: #770683 Cf. #735173 --- debian/changelog | 3 + debian/patches/00list | 1 + debian/patches/bts770683_curl_init.dpatch | 117 ++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100755 debian/patches/bts770683_curl_init.dpatch diff --git a/debian/changelog b/debian/changelog index f192cfe..dc739f2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,9 @@ collectd (5.4.1-6) UNRELEASED; urgency=medium - Added bts747093_lvm_segfault: upstream fix for a segfault in the LVM plugin; thanks to Bernd Zeimetz and Marc Fournier for reporting this (Closes: #747093). + - Added bts770683_curl_init: upstream fix for a segfault in plugins using + libcurl caused by concurrent memory access; thanks to Marc Fournier for + reporting this (Closes: #770683, cf. #735173). -- Sebastian Harl Sun, 23 Nov 2014 13:04:03 +0100 diff --git a/debian/patches/00list b/debian/patches/00list index f1f07e7..5046f3e 100644 --- a/debian/patches/00list +++ b/debian/patches/00list @@ -6,3 +6,4 @@ myplugin_api.dpatch bts559801_plugin_find_fix.dpatch bts770681_riemann_ack.dpatch bts747093_lvm_segfault.dpatch +bts770683_curl_init.dpatch diff --git a/debian/patches/bts770683_curl_init.dpatch b/debian/patches/bts770683_curl_init.dpatch new file mode 100755 index 0000000..d488ec8 --- /dev/null +++ b/debian/patches/bts770683_curl_init.dpatch @@ -0,0 +1,117 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## bts770683_curl_init.dpatch by Jeremy Katz +## +## DP: Call curl_global_init() in _init of plugins using curl. +## DP: +## DP: curl_global_init() or curl_easy_init() has to be called in the init +## DP: callback of plugins using curl while collectd still runs single +## DP: threaded. Else, collectd may crash with a segfault due to concurrent +## DP: memory access by curl. +## DP: +## DP: Upstream bug report: +## DP: https://github.com/collectd/collectd/issues/526 + +@DPATCH@ + +diff a/src/apache.c b/src/apache.c +--- a/src/apache.c ++++ b/src/apache.c +@@ -702,9 +702,18 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ + return (0); + } /* }}} int apache_read_host */ + ++static int apache_init (void) /* {{{ */ ++{ ++ /* Call this while collectd is still single-threaded to avoid ++ * initialization issues in libgcrypt. */ ++ curl_global_init (CURL_GLOBAL_SSL); ++ return (0); ++} /* }}} int apache_init */ ++ + void module_register (void) + { + plugin_register_complex_config ("apache", config); ++ plugin_register_init ("apache", apache_init); + } /* void module_register */ + + /* vim: set sw=8 noet fdm=marker : */ +diff a/src/curl.c b/src/curl.c +--- a/src/curl.c ++++ b/src/curl.c +@@ -566,6 +566,7 @@ static int cc_init (void) /* {{{ */ + INFO ("curl plugin: No pages have been defined."); + return (-1); + } ++ curl_global_init (CURL_GLOBAL_SSL); + return (0); + } /* }}} int cc_init */ + +diff --git a/src/curl_json.c b/src/curl_json.c +index 24e1df1..0948962 100644 +--- a/src/curl_json.c ++++ b/src/curl_json.c +@@ -882,9 +882,18 @@ static int cj_read (user_data_t *ud) /* {{{ */ + return cj_curl_perform (db, db->curl); + } /* }}} int cj_read */ + ++static int cj_init (void) /* {{{ */ ++{ ++ /* Call this while collectd is still single-threaded to avoid ++ * initialization issues in libgcrypt. */ ++ curl_global_init (CURL_GLOBAL_SSL); ++ return (0); ++} /* }}} int cj_init */ ++ + void module_register (void) + { + plugin_register_complex_config ("curl_json", cj_config); ++ plugin_register_init ("curl_json", cj_init); + } /* void module_register */ + + /* vim: set sw=2 sts=2 et fdm=marker : */ +diff --git a/src/curl_xml.c b/src/curl_xml.c +index b941f02..e31e73d 100644 +--- a/src/curl_xml.c ++++ b/src/curl_xml.c +@@ -926,9 +926,18 @@ static int cx_config (oconfig_item_t *ci) /* {{{ */ + return (0); + } /* }}} int cx_config */ + ++static int cx_init (void) /* {{{ */ ++{ ++ /* Call this while collectd is still single-threaded to avoid ++ * initialization issues in libgcrypt. */ ++ curl_global_init (CURL_GLOBAL_SSL); ++ return (0); ++} /* }}} int cx_init */ ++ + void module_register (void) + { + plugin_register_complex_config ("curl_xml", cx_config); ++ plugin_register_init ("curl_xml", cx_init); + } /* void module_register */ + + /* vim: set sw=2 sts=2 et fdm=marker : */ +diff --git a/src/write_http.c b/src/write_http.c +index 62c73b0..04c637b 100644 +--- a/src/write_http.c ++++ b/src/write_http.c +@@ -656,9 +656,18 @@ static int wh_config (oconfig_item_t *ci) /* {{{ */ + return (0); + } /* }}} int wh_config */ + ++static int wh_init (void) /* {{{ */ ++{ ++ /* Call this while collectd is still single-threaded to avoid ++ * initialization issues in libgcrypt. */ ++ curl_global_init (CURL_GLOBAL_SSL); ++ return (0); ++} /* }}} int wh_init */ ++ + void module_register (void) /* {{{ */ + { + plugin_register_complex_config ("write_http", wh_config); ++ plugin_register_init ("write_http", wh_init); + } /* }}} void module_register */ + + /* vim: set fdm=marker sw=8 ts=8 tw=78 et : */ -- 2.30.2