[DTrace-devel] [PATCH v3 17/19] strings: handle null strings in the ternary conditional op

Nick Alcock nick.alcock at oracle.com
Thu Mar 24 18:24:43 UTC 2022


This will fault if the result is a null string now that dt_cg_memcpy is
error-checked.  (It is not enough to make strings work: dt_cg_store_var
is doing the same thing, preventing you even *assigning* NULL to a
string. Not sure how to fix that.)

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
 libdtrace/dt_cg.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 656b45c34867..59e8c206979a 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -3673,6 +3673,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
@@ -3689,6 +3693,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);
 	}
-- 
2.35.1.261.g8402f930ba.dirty




More information about the DTrace-devel mailing list