Skip to content

Commit

Permalink
cg: support null pointers in ternary conditionals
Browse files Browse the repository at this point in the history
This lets you compare ternaries with NULL without risking a dereference.

(Some of the alloca tests can sometimes do this.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock committed Apr 19, 2022
1 parent 843ce03 commit cf3a3f4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3255,6 +3255,10 @@ dt_cg_ternary_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
* dn_right).
*/
if (dt_node_is_string(dnp)) {
uint_t lbl_null = dt_irlist_label(dlp);

emit(dlp, BPF_BRANCH_IMM(BPF_JEQ, dnp->dn_reg, 0, lbl_null));

/*
* At this point, dnp->dn_reg holds a pointer to the string we
* need to copy. But we want to copy it into a tstring which
Expand All @@ -3271,6 +3275,8 @@ dt_cg_ternary_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
dt_cg_memcpy(dlp, drp, dnp->dn_reg, BPF_REG_0,
yypcb->pcb_hdl->dt_options[DTRACEOPT_STRSIZE]);

emitl(dlp, lbl_null,
BPF_NOP());
dt_cg_tstring_free(yypcb, dnp->dn_left);
dt_cg_tstring_free(yypcb, dnp->dn_right);
}
Expand Down

0 comments on commit cf3a3f4

Please sign in to comment.