]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: converters: Store the sink in an arg pointer for debug() converter
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:00:23 +0000 (14:00 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:24:21 +0000 (14:24 +0200)
The debug() converter uses a string to reference the sink where to send debug
events. During the configuration parsing, this string is converted to a sink
object but it is still store as a string argument. It is a problem on deinit
because string arguments are released. So the sink pointer will be released
twice.

To fix the bug, we keep a reference on the sink using an ARGT_PTR argument. This
way, it will not be freed on the deinit.

This patch depends on the commit e02fc4d0d ("MINOR: arg: Add an argument type to
keep a reference on opaque data"). Both must be backported as far as 2.1.

src/sample.c

index 68b52acea19b34b5254b6b301e1d1dc37c525afa..2e221047b5fd1a5f7512feca1a70066f95ababa3 100644 (file)
@@ -1452,7 +1452,7 @@ static int sample_conv_debug(const struct arg *arg_p, struct sample *smp, void *
        if (!buf)
                goto end;
 
-       sink = (struct sink *)arg_p[1].data.str.area;
+       sink = (struct sink *)arg_p[1].data.ptr;
        BUG_ON(!sink);
 
        pfx = arg_p[0].data.str.area;
@@ -1514,8 +1514,8 @@ static int smp_check_debug(struct arg *args, struct sample_conv *conv,
                return 0;
        }
 
-       args[1].data.str.area = (char *)sink;
-       args[1].data.str.data = 0; // that's not a string anymore
+       args[1].type = ARGT_PTR;
+       args[1].data.ptr = sink;
        return 1;
 }