zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
243 stars 37 forks source link

Compiler segfault when using an non-literal with `%synchronize-at` #1775

Closed bbannier closed 1 month ago

bbannier commented 1 month ago

The current validation around at least %synchronize-at seems to miss cases where the given expression is not a literal. Before 28437292fcf01cb1602e0318924cd7c78f5429fe this would run forever, now it segfaults in the compiler.

module foo;

type A = unit {
    %synchronize-at = A;
    : /AA/;
};

public type X = unit {
    : (A &synchronize)[] ;
};
$ spicyc -dj foo.spicy
Assertion failed: (ctor_), function syncProduction, file parser-builder.cc, line 1215.
[1]    44368 abort      ./build/bin/spicyc -d foo.spicy -j
bbannier commented 1 month ago

@rsmmr I looked into adding a validation catching this, but it seems the only validation which gets invoked before the failed assert is for https://github.com/zeek/spicy/blob/117875bf61f3fcfb5756a8695d0ff04ed9bb5273/spicy/lib/spicy.spicy#L6 this module property. We do not seem to have any tests for e.g., the %synchronize-at attribute, https://github.com/zeek/spicy/blob/117875bf61f3fcfb5756a8695d0ff04ed9bb5273/spicy/toolchain/src/compiler/validator.cc#L321-L326

Could you look into what is going on here?