zeek/spicy

Cannot forward `const` data from filter

Closed this issue · 0 comments

Currently a filter's forward method claims to require inout bytes, but we always only copy the data. This makes it impossible to forward const data, e.g.,

module foo;

const C = b"";

type F = unit {
    %filter;
    : bytes &eod &convert=$$.split(b" ") {
        for (x in $$) {
            self.forward(x); # FAIL: `x` is `const`.
            self.forward(C); # FAIL: `C` is an actual `const`.
        }
    }
};

public type X = unit {
    on %init {
        self.connect_filter(new F);
    }
};
$ spicyc -j foo.spicy
[error] foo.spicy:9:13-9:27: unsupported operator: <foo::F>.forward(<const bytes>)
[error] foo.spicy:10:13-10:27: unsupported operator: <foo::F>.forward(<const bytes>)
[error] spicyc: aborting after errors

We should drop the inout requirement from forward.

As a workaround one currently could create a new local variable, e.g.,

            local y = C;
            self.forward(y); # WORKS.