6a97fac3ea79461badd440672ed5d615a9ab3181
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## bts750440_config_segfault.dpatch by Wilfried Goesgens <dothebart@citadel.org>
3 ##
4 ## DP: Fixed a segfault when handling/including empty config files.
5 ## DP:
6 ## DP: Correctly handle the case of empty "children" nodes.
7 ## DP:
8 ## DP: Upstream bug report:
9 ## DP: https://github.com/collectd/collectd/issues/638
11 @DPATCH@
13 diff a/src/configfile.c b/src/configfile.c
14 --- a/src/configfile.c
15 +++ b/src/configfile.c
16 @@ -414,6 +414,12 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src,
18 /* Resize the memory containing the children to be big enough to hold
19 * all children. */
20 + if (dst->children_num + src->children_num - 1 == 0)
21 + {
22 + dst->children_num = 0;
23 + return (0);
24 + }
25 +
26 temp = (oconfig_item_t *) realloc (dst->children,
27 sizeof (oconfig_item_t)
28 * (dst->children_num + src->children_num - 1));
29 @@ -514,7 +520,8 @@ static int cf_include_all (oconfig_item_t *root, int depth)
30 continue;
32 /* Now replace the i'th child in `root' with `new'. */
33 - cf_ci_replace_child (root, new, i);
34 + if (cf_ci_replace_child (root, new, i) < 0)
35 + return (-1);
37 /* ... and go back to the new i'th child. */
38 --i;