[DTrace-devel] [PATCH] cg, parser: fix handling of alloca()'d string values

Nick Alcock nick.alcock at oracle.com
Mon Feb 20 16:27:20 UTC 2023


On 18 Feb 2023, Kris Van Hees via DTrace-devel stated:

> When alloca()'d memory is used as a string, special handling is needed
> to ensure variable assignment and storing in the output buffer works
> correctly.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>

No idea how I didn't spot this myself (well, except that I never
thought of the test that shows it), but

Reviewed-by: Nick Alcock <nick.alcock at oracle.com>

Nice tests!

> diff --git a/test/unittest/actions/printf/tst.conv_s_copyin.d b/test/unittest/actions/printf/tst.conv_s_copyin.d
> new file mode 100644
> index 00000000..11e7745f
> --- /dev/null
> +++ b/test/unittest/actions/printf/tst.conv_s_copyin.d
> @@ -0,0 +1,27 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, 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: The printf action supports '%s' for copyin()'d string values.
> + *
> + * SECTION: Actions/printf()
> + */
> +/* @@trigger: delaydie */
> +
> +#pragma D option quiet
> +
> +syscall::write:entry
> +/pid == $target/
> +{
> +	printf("'%s'", (string)copyin(arg1, 32));

Relying on delaydie for its error output is, er, not really what I
thought this trigger would be used for when I wrote it! Looks like most
of its users do that now. We might want to rename it to something that
better indicates its other purpose one of these days.

> diff --git a/test/unittest/funcs/bcopy/err.bcopy-into-string.d b/test/unittest/funcs/bcopy/err.bcopy-into-string.d
> new file mode 100644
> index 00000000..4529a609
> --- /dev/null
> +++ b/test/unittest/funcs/bcopy/err.bcopy-into-string.d
> @@ -0,0 +1,18 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, 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: A bcopy() into an alloca()'d string variable yields an error.
> + *
> + * SECTION: Actions and Subroutines/bcopy()
> + */
> +
> +BEGIN {
> +	s = (string)alloca(10);
> +	bcopy(probename, s, 5);
> +	exit(0);
> +}

I generally capture expected results for err.* tests, or add tags to
them (where possible), so that we can at least make sure the error
doesn't silently change on us. (But it's certainly true that lots of
err.* tests don't do either.)

-- 
NULL && (void)



More information about the DTrace-devel mailing list