[DTrace-devel] [PATCH] cg: ensure argument NULL pointer check detects constant 0 values

Kris Van Hees kris.van.hees at oracle.com
Sat Sep 16 04:31:32 UTC 2023


The dt_cg_arg_to_tstring() function was generating code for a runtime
NULL pointer check if the passed argument was a pointer or a string.
But if the passed argument was a NULL constant, that check was never
generated because the argument was an integer in that case.

The new code determines the need for the NULL pointer check based on
the datatype of the argument (as specified in the function prototype)
instead.

Tests are included based on inet_ntoa6().

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cg.c                             |  9 ++++++++-
 ...a6badaddr.d => err.inet_ntoa6.arg1_null.d} |  0
 .../err.inet_ntoa6.arg1_null_const.d          | 19 +++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)
 rename test/unittest/funcs/inet_ntoa6/{err.inet_ntoa6badaddr.d => err.inet_ntoa6.arg1_null.d} (100%)
 create mode 100644 test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null_const.d

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 3a9f8d4d..86ee6908 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -4642,13 +4642,20 @@ dt_cg_subr_arg_to_tstring(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp,
 {
 	dt_ident_t	*idp;
 	dt_node_t	*arg = dnp->dn_args;
+	dt_idsig_t	*isp;
+	dt_node_t	*argtype;
 
 	TRACE_REGSET("    subr-arg_to_tstring:Begin");
 
+	assert(dnp->dn_ident && dnp->dn_ident);
+	isp = dnp->dn_ident->di_data;
+	assert(isp && isp->dis_args);
+	argtype = &isp->dis_args[0];
+
 	/* handle the one "input value" */
 	/* (its type matters only as to whether we check it is null */
 	dt_cg_node(arg, dlp, drp);
-	if (dt_node_is_pointer(arg) || dt_node_is_string(arg))
+	if (dt_node_is_pointer(argtype) || dt_node_is_string(argtype))
 		dt_cg_check_ptr_arg(dlp, drp, arg, NULL);
 
 	/* allocate the temporary string */
diff --git a/test/unittest/funcs/inet_ntoa6/err.inet_ntoa6badaddr.d b/test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null.d
similarity index 100%
rename from test/unittest/funcs/inet_ntoa6/err.inet_ntoa6badaddr.d
rename to test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null.d
diff --git a/test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null_const.d b/test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null_const.d
new file mode 100644
index 00000000..f5881d40
--- /dev/null
+++ b/test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null_const.d
@@ -0,0 +1,19 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2023, 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.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	inet_ntoa6(NULL);
+	exit(0);
+}
+
+ERROR
+{
+	exit(1);
+}
-- 
2.40.1




More information about the DTrace-devel mailing list