Skip to content

Commit

Permalink
cg: ensure argument NULL pointer check detects constant 0 values
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eugene Loh <[email protected]>
  • Loading branch information
kvanhees committed Sep 23, 2023
1 parent 6e4d2b0 commit 450e5b5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

-- @@stderr --
dtrace: error on enabled probe ID 3 (ID 1: dtrace:::BEGIN): invalid address ({ptr}) in action #1 at BPF pc NNN
19 changes: 19 additions & 0 deletions test/unittest/funcs/inet_ntoa6/err.inet_ntoa6.arg1_null_const.d
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

-- @@stderr --
dtrace: error on enabled probe ID 3 (ID 1: dtrace:::BEGIN): invalid address ({ptr}) in action #1 at BPF pc NNN

0 comments on commit 450e5b5

Please sign in to comment.