[Bro-Dev] Some bro.bif issues

Gregor Maier gregor at icir.org
Fri Nov 18 21:11:33 PST 2011

On 11/18/11 19:14 , Matthias Vallentin wrote:
> This is the function set_buf:
>      function set_buf%(f: file, buffered: bool%): any
>          %{
>          f->SetBuf(buffered);
>          return new Val(0, TYPE_VOID);
>          %}
> It's return value is any although void is returned. Shouldn't the return value
> in the function signature be void as well?

Except for this one, all BiF's that don't have a return value are 
declared as returning "any" and will unconditionally do a "return 0"...

AFAIK BiF's currently can't return void. Although I think that's just 
(an easily fixed) limitation of the BiF-parser.
So I guess that either this BiF should be changed to return 0 to be 
consistent with other BiFs. Or the BiF-parser should be changed to allow 
void as return value and the BiF's updated accordingly. Might want to 
schedule this for 2.1 or 2.2....

> Moreover, here is the function exit:
>      function exit%(%): int
>          %{
>          exit(0);
>          return 0;
>          %}

Per the above. Currently it should return an "any" to be consistent with 
other code.

(Search for "return 0" in any BiF file and you'll find plenty of 
functions that should return void but do in fact return "any")

>      function active_connection%(id: conn_id%): bool
>      function connection_exists%(c: conn_id%): bool
> are essentially the same. Only the latter is used in the current set of
> scripts. Should we get rid of the former?

sounds good. The latter is also the more intuitive name....

> The same sort of redundancy exists for:
>      function connection_record%(cid: conn_id%): connection
>      function lookup_connection%(cid: conn_id%): connection
> except that the latter returns a dummy connection value. Neither function is
> currently used at script land. My vote would be to remove the former one, as
> the latter has more graceful semantics.

We for sure shouldn't call exit() when the connection doesn't exist...

Gregor Maier
<gregor at icir.org>  <gregor at icsi.berkeley.edu>
Int. Computer Science Institute (ICSI)
1947 Center St., Ste. 600
Berkeley, CA 94704, USA

More information about the bro-dev mailing list