[DTrace-devel] [PATCH] agg: report error if aggsize too small to fit an aggregation

Kris Van Hees kris.van.hees at oracle.com
Thu Mar 16 03:01:40 UTC 2023


Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_bpf.c                         |  6 ++++-
 test/unittest/aggs/err.aggsize-too-small.d | 27 ++++++++++++++++++++++
 test/unittest/aggs/err.aggsize-too-small.r |  3 +++
 3 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/aggs/err.aggsize-too-small.d
 create mode 100644 test/unittest/aggs/err.aggsize-too-small.r

diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index 18aa07af..5b77bf9a 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -521,8 +521,12 @@ gmap_create_aggs(dtrace_hdl_t *dtp)
 	nelems = dtp->dt_options[DTRACEOPT_AGGSIZE] /
 		 (dtp->dt_maxtuplesize + dtp->dt_maxaggdsize);
 
+	/*
+	 * We know aggregations are being used, so if aggsize is so small that
+	 * even a single aggregation won't fit, we cannot proceed.
+	 */
 	if (nelems == 0)
-		return 0;
+		return dt_set_errno(dtp, EDT_BUFTOOSMALL);
 
 	dtp->dt_aggmap_fd = create_gmap_of_maps(dtp, "aggs",
 						BPF_MAP_TYPE_ARRAY_OF_MAPS,
diff --git a/test/unittest/aggs/err.aggsize-too-small.d b/test/unittest/aggs/err.aggsize-too-small.d
new file mode 100644
index 00000000..8d73baf8
--- /dev/null
+++ b/test/unittest/aggs/err.aggsize-too-small.d
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/*
+ * ASSERTION: If aggsize is too small to hold a single aggregation, an error
+ *	      is reported.
+ *
+ * SECTION: Aggregations/Aggregations
+ */
+
+#pragma D option aggsize=256
+#pragma D option strsize=256
+
+BEGIN
+{
+	@["a"] = count();
+	exit(0);
+}
+
+ERROR
+{
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.aggsize-too-small.r b/test/unittest/aggs/err.aggsize-too-small.r
new file mode 100644
index 00000000..b0a37c5d
--- /dev/null
+++ b/test/unittest/aggs/err.aggsize-too-small.r
@@ -0,0 +1,3 @@
+-- @@stderr --
+dtrace: script 'test/unittest/aggs/err.aggsize-too-small.d' matched 2 probes
+dtrace: could not enable tracing: Enabling exceeds size of buffer
-- 
2.39.1




More information about the DTrace-devel mailing list