bifcl: Render runtime type checks for var_args bifs

Currently, Zeek disables any static type checking for var_arg bifs.
However, the generated preamble for var_args bifs assume that
typed positional arguments are correctly typed and blindly calls
the type converters on them. This easily triggers abort()s at runtime
currently when a script mistakenly uses the wrong types for var_arg
bifs. For example, calling publish_rr() with a port instead of a string
causes a hard-abort with Zeek 5.0.8.

    $ zeek -e 'Cluster::publish_rr(Cluster::Pool(), 80/tcp)'
    fatal error in <no location>: Val::CONVERTER (port/string) (80/tcp)
    Aborted (core dumped)

Extend bifcl so that for var_arg functions and the types that bifcl understands,
we render a runtime type check and explicit early return to avoid the abort().
For any/other types, the implementer of the bif continuous to be responsible
for type checking.

This isn't solving the var_args situation generally, but avoids some
ad-hoc fixes trickling in current bif implementations.

Some references:

https://github.com/zeek/zeek/issues/1523
https://github.com/zeek/zeek/issues/2425
https://github.com/zeek/zeek/issues/2935
https://github.com/zeek/zeek/pull/2950
This commit is contained in:
Arne Welzel 2023-04-19 14:15:09 +02:00 committed by Tim Wojtulewicz
parent efb32d31fc
commit e7cce57f2b
3 changed files with 26 additions and 9 deletions

View file

@ -25,7 +25,7 @@ public:
int Type() const { return type; }
void PrintZeek(FILE* fp);
void PrintCDef(FILE* fp, int n);
void PrintCDef(FILE* fp, int n, bool runtime_type_check = false);
void PrintCArg(FILE* fp, int n);
void PrintValConstructor(FILE* fp);