Skip to contentSkip to conversation

Cast should not change writable

PATCH In review [email protected] 2 participants 2 messages Oct 22, 2024 – Oct 28, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cast should not change writable

From: Eugene Loh <[email protected]>

---
 libdtrace/dt_parser.c                  |  4 ++++
 test/unittest/types/tst.castwritable.d | 22 ++++++++++++++++++++++
 test/unittest/types/tst.castwritable.r |  1 +
 3 files changed, 27 insertions(+)
 create mode 100644 test/unittest/types/tst.castwritable.d
 create mode 100644 test/unittest/types/tst.castwritable.r
libdtrace/dt_parser.c +4 -0
index 59293ebce..325ba881e 100644
@@ -4209,6 +4209,10 @@ asgn_common:
 			dt_cook_taint_alloca(lp, NULL, rp);
 
 		dt_node_type_propagate(lp, dnp); /* see K&R[A7.5] */
+
+		if (rp->dn_flags & DT_NF_WRITABLE)
+			dnp->dn_flags |= DT_NF_WRITABLE;
+
 		dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
 		break;
 	}
test/unittest/types/tst.castwritable.d new file +22 -0
new file mode 100644
index 000000000..1b419228c
@@ -0,0 +1,22 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2024, 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.
+ */
+
+/*
+ * ASSERTION:  casting keeps a variable writable.
+ *
+ * SECTION: Types, Operators, and Expressions/Constants
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	x = (char *) alloca(8);
+	*((long long*)x) = 0x0067666564636261;
+	trace(stringof(x));
+	exit(0);
+}
test/unittest/types/tst.castwritable.r new file +1 -0
new file mode 100644
index 000000000..b5b9ef6c6
@@ -0,0 +1 @@
+abcdefg
Signature · 1 line
2.43.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · On Tue, Oct 22, 2024 at 04:47:27PM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

Quoted 61 lines
---
 libdtrace/dt_parser.c                  |  4 ++++
 test/unittest/types/tst.castwritable.d | 22 ++++++++++++++++++++++
 test/unittest/types/tst.castwritable.r |  1 +
 3 files changed, 27 insertions(+)
 create mode 100644 test/unittest/types/tst.castwritable.d
 create mode 100644 test/unittest/types/tst.castwritable.r
libdtrace/dt_parser.c +4 -0
index 59293ebce..325ba881e 100644
@@ -4209,6 +4209,10 @@ asgn_common:
 			dt_cook_taint_alloca(lp, NULL, rp);
 
 		dt_node_type_propagate(lp, dnp); /* see K&R[A7.5] */
+
+		if (rp->dn_flags & DT_NF_WRITABLE)
+			dnp->dn_flags |= DT_NF_WRITABLE;
+
 		dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
 		break;
 	}
test/unittest/types/tst.castwritable.d new file +22 -0
new file mode 100644
index 000000000..1b419228c
@@ -0,0 +1,22 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2024, 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.
+ */
+
+/*
+ * ASSERTION:  casting keeps a variable writable.
+ *
+ * SECTION: Types, Operators, and Expressions/Constants
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	x = (char *) alloca(8);
+	*((long long*)x) = 0x0067666564636261;
+	trace(stringof(x));
+	exit(0);
+}
test/unittest/types/tst.castwritable.r new file +1 -0
new file mode 100644
index 000000000..b5b9ef6c6
@@ -0,0 +1 @@
+abcdefg
Signature · 1 line
2.43.5