[syslog-ng] [PATCH] basicfuncs: Implement a few numeric template functions.

Gergely Nagy algernon at balabit.hu
Tue May 3 10:44:30 CEST 2011


Gergely Nagy <algernon at balabit.hu> writes:

> From: Gergely Nagy <algernon at madhouse-project.org>
>
> Implement addition, substraction, multiplication, division and modulus
> template functions: $(+ N M), $(- N M), $(* N M), $(/ N M) and $(% N
> M), respectively.

Aand, while reviewing this code with Viktor Juhasz, we spotted a mistake
in the code below:

> +static void
> +tf_num_div(LogMessage *msg, gint argc, GString *argv[], GString *result)
> +{
> +  glong n, m;
> +
> +  if (!tf_num_parse(argc, argv, "/", &n, &m))
> +    return;
> +
> +  g_string_append_printf(result, "%li", (glong)(n / m));
> +}

If m is 0, this will crash syslog-ng. I'll repost a version of the patch
that guards against this later today.

$(/ $FOO 0) will emit an msg_error and do nothing.

-- 
|8]


More information about the syslog-ng mailing list