From fd86d8530bf5800c92d3f4952fa3bb2b9d788f79 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Fri, 26 May 2023 11:17:48 +0200 Subject: [PATCH 1/2] Fix disappearing unit fields in Spicy type export. When a Spicy unit type was used in an EVT event definition, it could end up being cleared out at the time the logic for `export` got to see it. Closes #3083. Note: This needs backporting to the legacy plugin. --- src/spicy/spicyz/glue-compiler.cc | 2 +- .../Baseline/spicy.export-type-e2e/output | 3 ++ testing/btest/spicy/export-type-e2e.zeek | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 testing/btest/Baseline/spicy.export-type-e2e/output create mode 100644 testing/btest/spicy/export-type-e2e.zeek diff --git a/src/spicy/spicyz/glue-compiler.cc b/src/spicy/spicyz/glue-compiler.cc index b1fbc28a62..0815876552 100644 --- a/src/spicy/spicyz/glue-compiler.cc +++ b/src/spicy/spicyz/glue-compiler.cc @@ -985,7 +985,7 @@ bool GlueCompiler::PopulateEvents() { } } - ev.unit_type = std::move(uinfo.type.as<::spicy::type::Unit>()); + ev.unit_type = uinfo.type.as<::spicy::type::Unit>(); ev.unit_module_id = uinfo.module_id; ev.unit_module_path = uinfo.module_path; diff --git a/testing/btest/Baseline/spicy.export-type-e2e/output b/testing/btest/Baseline/spicy.export-type-e2e/output new file mode 100644 index 0000000000..97c098fbaf --- /dev/null +++ b/testing/btest/Baseline/spicy.export-type-e2e/output @@ -0,0 +1,3 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +[x=71] +[x=72] diff --git a/testing/btest/spicy/export-type-e2e.zeek b/testing/btest/spicy/export-type-e2e.zeek new file mode 100644 index 0000000000..6140c2eb4f --- /dev/null +++ b/testing/btest/spicy/export-type-e2e.zeek @@ -0,0 +1,31 @@ +# @TEST-REQUIRES: have-spicy +# +# @TEST-EXEC: spicyz -do export.hlto export.spicy export.evt +# @TEST-EXEC: zeek -Cr $TRACES/http/pipelined-requests.trace export.hlto %INPUT >>output +# @TEST-EXEC: test '!' -e reporter.log +# @TEST-EXEC: btest-diff output +# +# @TEST-DOC: Test type export end-to-end, with access from the Zeek side. Regression test for #3083. + +# @TEST-START-FILE export.spicy +module foo; + +public type X = unit { + x: uint8; +}; +# @TEST-END-FILE + +# @TEST-START-FILE export.evt +import foo; + +protocol analyzer FOO over TCP: + parse with foo::X, + port 1/tcp-40000/tcp; + +export foo::X; + +on foo::X -> event foo::hello(self); +# @TEST-END-FILE + +event foo::hello(x: foo::X) + { print x; } From 0b100c1e1c89ef5d90b5e6d7c16eb82e9a6a8645 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Sun, 28 May 2023 17:36:06 +0200 Subject: [PATCH 2/2] Register test analyzer only for required ports. This is a workaround for #3094. --- testing/btest/spicy/export-type-e2e.zeek | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/btest/spicy/export-type-e2e.zeek b/testing/btest/spicy/export-type-e2e.zeek index 6140c2eb4f..ce9b402b1b 100644 --- a/testing/btest/spicy/export-type-e2e.zeek +++ b/testing/btest/spicy/export-type-e2e.zeek @@ -20,7 +20,7 @@ import foo; protocol analyzer FOO over TCP: parse with foo::X, - port 1/tcp-40000/tcp; + port 80/tcp; export foo::X;