zeek / spicy

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

`skip` field can't receive parameters #1852

Closed AmazingPP closed 1 week ago

AmazingPP commented 2 weeks ago

I have some variable length data that needs to be skipped, similar to the following example:

module Test;

type Ctx = tuple<is_large_pad: bool>;

public type Testing = unit {
    %context = Ctx;

    padding: skip Pad(self.context());
    data: bytes &eod;

    on %init { self.context().is_large_pad = True; }
    on %done { print self; }
};

type Pad = unit(c: Ctx&) {
    : skip uint8;
    : skip uint8[3] if ( c.is_large_pad );
};

But this doesn't work

printf '\01\02\03\04Foo' | spicy-driver test.spicy
[error] terminating with uncaught exception of type hilti::rt::NullReference: attempt to access null reference (test.spicy:17:5-17:42)

When I removed the skip keyword from padding, everything worked fine

-    padding: skip Pad(self.context());
+   : Pad(self.context());
printf '\01\02\03\04Foo' | spicy-driver test.spicy
[$padding=[], $data=b"Foo"]