[DTrace-devel] [PATCH 05/13] Handle steps==0 error for llquantize

Kris Van Hees kris.van.hees at oracle.com
Tue Dec 8 08:15:55 PST 2020


On Wed, Dec 02, 2020 at 01:54:50PM -0500, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> We can get divide-by-zero failures if we do not explicitly check.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  libdtrace/dt_cg.c                             |  2 +-
>  .../aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d | 20 +++++++++++++++++++
>  2 files changed, 21 insertions(+), 1 deletion(-)
>  create mode 100644 test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d
> 
> diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
> index 29426d23..673b9794 100644
> --- a/libdtrace/dt_cg.c
> +++ b/libdtrace/dt_cg.c
> @@ -3216,7 +3216,7 @@ dt_cg_agg_llquantize(dt_pcb_t *pcb, dt_ident_t *aid, dt_node_t *dnp,
>  			"must be an unsigned 16-bit quantity\n");
>  
>  	if (steps < factor) {
> -		if (factor % steps != 0)
> +		if (steps == 0 || factor % steps != 0)
>  			dnerror(arg1, D_LLQUANT_STEPVAL, "llquantize() "
>  				"argument #4 (steps) must evenly divide "
>  				"argument #1 (factor) when steps<factor\n");

I think it would be better to match what lquantize() does (and as should have
been done when llquantize was originally implemented)

                if (!dt_node_is_posconst(arg4))
                        dnerror(arg3, D_LLQUANT_STEPTYPE, "llquantize( ) "
                                "argument #4 must be a non-zero positive "
                                "integer constant\n");

> diff --git a/test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d b/test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d
> new file mode 100644
> index 00000000..f2b0f442
> --- /dev/null
> +++ b/test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d
> @@ -0,0 +1,20 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION:
> + *  llquantize() steps must be nonzero.
> + *
> + * SECTION: Aggregations/Aggregations
> + *
> + */
> +
> +
> +BEGIN
> +{
> +	@ = llquantize(timestamp, 10, 0, 6, 0);
> +}
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list