[DTrace-devel] [PATCH] Add tstring free test

eugene.loh at oracle.com eugene.loh at oracle.com
Tue Dec 7 19:59:28 UTC 2021


From: Eugene Loh <eugene.loh at oracle.com>

Commit cd179d39f759
("Ensure proper validation checks are done before freeing a tstring")
was supposed to have included a test.  Add it.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_cg.c                        |  1 +
 test/unittest/codegen/tst.tstring_free.d | 29 ++++++++++++++++++++++++
 test/unittest/codegen/tst.tstring_free.r |  1 +
 3 files changed, 31 insertions(+)
 create mode 100644 test/unittest/codegen/tst.tstring_free.d
 create mode 100644 test/unittest/codegen/tst.tstring_free.r

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 48a61b8f..ed05b789 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -877,6 +877,7 @@ dt_cg_tstring_xfree(dt_pcb_t *pcb, uint64_t offset)
 	}
 
 	assert(i < DT_TSTRING_SLOTS);
+	assert(ts->in_use != 0);
 
 	ts->in_use = 0;
 }
diff --git a/test/unittest/codegen/tst.tstring_free.d b/test/unittest/codegen/tst.tstring_free.d
new file mode 100644
index 00000000..71c70463
--- /dev/null
+++ b/test/unittest/codegen/tst.tstring_free.d
@@ -0,0 +1,29 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2021, 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.
+ */
+
+/*
+ * Stress test some tstring-free cases.
+ */
+
+#pragma D option quiet
+
+BEGIN {
+	trace(
+	    (x = strjoin("abc", "def")) ==
+	    (y = strjoin("abc", "def")) ? 0 : 1);
+	trace(strjoin(
+	    (x = strjoin("abc", "def")),
+	    (y = strjoin("ABC", "DEF"))));
+	trace(substr(
+	    (x = strjoin("123", "456")),
+	    2));
+	trace(x = strjoin("abc", "def"));
+	trace(x =
+	    (y = strjoin("ABC", "DEF")));
+
+	exit(0);
+}
diff --git a/test/unittest/codegen/tst.tstring_free.r b/test/unittest/codegen/tst.tstring_free.r
new file mode 100644
index 00000000..bdc7cf65
--- /dev/null
+++ b/test/unittest/codegen/tst.tstring_free.r
@@ -0,0 +1 @@
+0abcdefABCDEF3456abcdefABCDEF
-- 
2.18.4




More information about the DTrace-devel mailing list