[DTrace-devel] [PATCH] Fix tstring free in string comparisons

Kris Van Hees kris.van.hees at oracle.com
Thu Oct 14 11:53:27 PDT 2021


Since this is referred to as a fix, I think you should probably put some
content in the commit msg what the problem is that is being fixed?

Otherthan that...  Reviewed-by.

On Thu, Oct 14, 2021 at 02:04:18PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  libdtrace/dt_cg.c                        |  6 ++++--
>  test/unittest/codegen/tst.tstring_free.d | 18 ++++++++++++++++++
>  test/unittest/codegen/tst.tstring_free.r |  1 +
>  3 files changed, 23 insertions(+), 2 deletions(-)
>  create mode 100644 test/unittest/codegen/tst.tstring_free.d
>  create mode 100644 test/unittest/codegen/tst.tstring_free.r
> 
> diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
> index 5d9fb26f..3cf4cee4 100644
> --- a/libdtrace/dt_cg.c
> +++ b/libdtrace/dt_cg.c
> @@ -2766,9 +2766,11 @@ dt_cg_compare_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, uint_t op)
>  		dt_cg_tstring_xfree(yypcb, off1);
>  		dt_cg_tstring_xfree(yypcb, off2);
>  
> -		if (dnp->dn_left->dn_tstring)
> +		if (dnp->dn_left->dn_kind == DT_NODE_FUNC &&
> +		    dnp->dn_left->dn_tstring)
>  			dt_cg_tstring_free(yypcb, dnp->dn_left);
> -		if (dnp->dn_right->dn_tstring)
> +		if (dnp->dn_right->dn_kind == DT_NODE_FUNC &&
> +		    dnp->dn_right->dn_tstring)
>  			dt_cg_tstring_free(yypcb, dnp->dn_right);
>  
>  		/* proceed with the comparison */
> diff --git a/test/unittest/codegen/tst.tstring_free.d b/test/unittest/codegen/tst.tstring_free.d
> new file mode 100644
> index 00000000..65b3b0f2
> --- /dev/null
> +++ b/test/unittest/codegen/tst.tstring_free.d
> @@ -0,0 +1,18 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2021, 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.
> + */
> +
> +/*
> + * Stress test some tstring-free cases.
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN {
> +	trace((x = substr("abcdef", 2)) == NULL ? 0 : 1);
> +	trace((x = strjoin("abc", "def")) == NULL ? 0 : 1);
> +	exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.tstring_free.r b/test/unittest/codegen/tst.tstring_free.r
> new file mode 100644
> index 00000000..b4de3947
> --- /dev/null
> +++ b/test/unittest/codegen/tst.tstring_free.r
> @@ -0,0 +1 @@
> +11
> -- 
> 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