Commit graph

308 commits

Author SHA1 Message Date
Jon Siwek
3521a92a00 Detect functions that try to bind variables from an outer scope.
And raise an error saying that's not supported.
Addresses BIT-1233.
2014-08-22 16:49:10 -05:00
Jon Siwek
e616554ab8 Fix use-after-free in some cases of reassigning a table index.
Specifically observed when redef'ing the same index of a table that uses
subnets as indices, though the bug seems like it applies more generally
to anytime TableVal::Assign is provided with just the HashKey parameter
and not the index Val.

Addresses BIT-1202.
2014-06-10 13:38:32 -05:00
Jon Siwek
aee708c703 Change record ctors to only allow record-field-assignment expressions.
Previously, any expression that evaluates to a record may have been used
in a record ctor's expression list.  This didn't work in all cases,
doesn't provide any unique functionality that can't be done otherwise,
and is possibly a path to introducing subtle scripting errors.

BIT-1192 #closed
2014-05-19 15:50:00 -05:00
Jon Siwek
9a8226935d Add unit tests covering vector/set/table ctors/inits. 2014-03-21 09:22:03 -05:00
Jon Siwek
bf3c3887fd Fix parsing of "local" named table constructors. 2014-03-20 16:47:20 -05:00
Jon Siwek
b1fd161274 Improve type checking of records, addresses BIT-1159. 2014-03-20 13:54:26 -05:00
Jon Siwek
da338c8ffe Teach async DNS lookup builtin-functions about BRO_DNS_FAKE.
And enable fake DNS mode for test suites.

Addresses BIT-1134.
2014-03-10 16:51:04 -05:00
Bernhard Amann
b3bd509b3f Allow iterating over bif functions with result type vector of any.
This changes the internal type that is used to signal that a vector
is unspecified from any to void.

I tried to verify that the behavior of Bro is still the same. After
a lot of playing around, I think everything still should worl as before.

However, it might be good for someone to take a look at this.

addresses BIT-1144
2014-02-25 15:30:29 -08:00
Robin Sommer
18bd20fe29 Fixing initialization context in anonymous functions.
When an anonymoys function was defined inside an initialization
context, that context transfered over to the function body and could
lead to spurious error messages.
2014-01-23 14:18:30 -08:00
Jon Siwek
58c7fcbbf1 Canonify output of a unit test. 2013-12-20 11:44:06 -06:00
Robin Sommer
ae9e0d4cb6 Fixing segfault with mismatching set &default in record field. 2013-12-18 09:17:05 -08:00
Jon Siwek
8515d3aa57 Support omission of string slice low/high indices, BIT-1097.
Omission of the low index defaults to 0:

    s = "12345"; s[:3] == "123"

Omission of the high index defaults to length of the string:

    s = "12345"; s[3:] == "45"
2013-12-04 15:11:48 -06:00
Jon Siwek
4014cdc277 Fix string slice notation, addresses BIT-1097.
Slice ranges were not correctly determined for negative indices and also
off by one in general (included one more element at the end of the
substring than what actually matched the index range).

It's now equivalent to Python slice notation.  Accessing a string at
a single index is also the same as Python except that an out-of-range
index returns an empty string instead of throwing an expection.
2013-12-03 14:39:21 -06:00
Jon Siwek
7e95755ce5 Fix record coercion tolerance of optional fields.
There were cases where coercing a record value with an uninitialized
field could cause a null pointer dereference even though the field
can validly be unset since it has &optional.
2013-10-23 11:37:23 -05:00
Jon Siwek
ae5a75bad9 Fix redef of table index from clearing table. Addresses #1013.
`redef foo["x"] = 1` now acts like `redef foo += { ["x"] = 1 }`
instead of `redef foo = { ["x"] = 1 }`.
2013-06-12 15:18:58 -05:00
Jon Siwek
022ce2505f Change @PATH to @DIR for clarity. Add @FILENAME. Addresses #869.
@DIR expands to directory path of the script, @FILENAME expands to just
the script file name without path.
2013-06-05 11:01:11 -05:00
Jon Siwek
7e8b504305 Make @PATH always return absolute path. Addresses #869. 2013-06-04 14:16:56 -05:00
Jon Siwek
307fc187c0 Add @PATH bro script macro. Addresses #869.
The macro expands to a string value containing the file system path
in which the script lives.
2013-06-04 10:53:10 -05:00
Jon Siwek
a66b7380b6 Allow named vector constructors. Addresses #983. 2013-05-30 10:57:28 -05:00
Jon Siwek
bcf5c41786 Allow named table constructors. Addresses #983. 2013-05-30 10:21:15 -05:00
Jon Siwek
29740d3d6e Improve set constructor argument coercion. 2013-05-29 16:49:12 -05:00
Jon Siwek
b256642f27 Allow named set constructors. Addresses #983. 2013-05-29 15:11:44 -05:00
Jon Siwek
a0ad87b4c2 Allow named record constructors. Addresses #983. 2013-05-29 12:48:15 -05:00
Jon Siwek
e2a1d4a233 Allow default function/hook/event parameters. Addresses #972.
And changed the endianness parameter of bytestring_to_count() BIF to
default to false (big endian), mostly just to prove that the BIF parser
doesn't choke on default parameters.
2013-05-07 14:32:22 -05:00
Jon Siwek
6a7a242db9 Table lookups return copy of non-const &default vals (addresses #981).
This prevents unintentional modifications to the &default value itself.
2013-05-03 11:22:15 -05:00
Robin Sommer
e986247ff2 Merge remote-tracking branch 'origin/topic/jsiwek/974'
Closes #974.

* origin/topic/jsiwek/974:
  Fix schedule statements used outside event handlers (addresses #974).
2013-04-23 20:38:21 -07:00
Jon Siwek
7069f679c3 Fix record coercion for default inner record fields (addresses #973). 2013-04-23 09:57:55 -05:00
Jon Siwek
fa30d4a313 Fix schedule statements used outside event handlers (addresses #974). 2013-04-22 13:00:44 -05:00
Robin Sommer
4255205026 Merge remote-tracking branch 'origin/topic/jsiwek/table-init-record-idx'
Closes #660.

* origin/topic/jsiwek/table-init-record-idx:
  Fix record constructors in table initializer indices.  Addresses #660.
2013-03-22 12:11:29 -07:00
Jon Siwek
2293443ea0 Fix function type-equivalence requiring same param names, addresses #957 2013-03-07 13:02:33 -06:00
Robin Sommer
9f99a4a942 Merge remote-tracking branch 'origin/topic/jsiwek/local-container-init'
Closes #952.

* origin/topic/jsiwek/local-container-init:
  Fix init of local sets/vectors via curly brace initializer lists.
2013-03-06 15:11:10 -08:00
Jon Siwek
c88babf6ef Fix init of local sets/vectors via curly brace initializer lists. 2013-03-01 16:42:16 -06:00
Jon Siwek
7e5115460c Fix three bugs with 'when' and 'return when' statements. Addresses #946
- 'when' statements were problematic when used in a function/event/hook
  that had local variables with an assigned function value.  This was
  because 'when' blocks operate on a clone of the frame and the cloning
  process serializes locals and the serialization of functions had an
  infinite cycle in it (ID -> BroFunc -> ID -> BroFunc ...).  The ID
  was only used for the function name and type information, so
  refactoring Func and subclasses to depend on those two things instead
  fixes the issue.

- 'return when' blocks, specifically, didn't work whenever execution
  of the containing function's body does another function call before
  reaching the 'return when' block, because of an assertion.  This was
  was due to logic in CallExpr::Eval always clearing the CallExpr
  associated with the Frame after doing the call, instead of restoring
  any previous CallExpr, which the code in Trigger::Eval expected to
  have available.

- An assert could be reached when the condition of a 'when' statement
  depended on checking the value of global state variables.  The assert
  in Trigger::QueueTrigger that checks that the Trigger isn't disabled
  would get hit because Trigger::Eval/Timeout disable themselves after
  running, but don't unregister themselves from the NotifierRegistry,
  which keeps calling QueueTrigger for every state access of the global.
2013-02-19 11:38:17 -06:00
Jon Siwek
69afc4a882 Add an error for record coercions that would orphan a field.
These cases should be avoidable by fixing scripts where they occur and
they can also help catch typos that would lead to unintentional runtime
behavior.

Adding this already revealed several scripts where a field in an inlined
record was never removed after a code refactor.
2013-01-24 09:56:19 -06:00
Robin Sommer
ed165f22a2 Making a test portable. 2013-01-23 19:43:52 -08:00
Robin Sommer
c780bfdb48 Merge remote-tracking branch 'origin/topic/jsiwek/ticket-932'
* origin/topic/jsiwek/ticket-932:
  Fix uninitialized locals in event/hook handlers from having a value.

Closes #932.
2013-01-23 15:17:55 -08:00
Robin Sommer
dcd675280e Merge remote-tracking branch 'origin/topic/jsiwek/no-switch-fallthrough'
* origin/topic/jsiwek/no-switch-fallthrough:
  Add "fallthrough" keyword, require a flow statement to end case blocks.
  Disable automatic case fallthrough in switch stmts.  Addresses #754.

I've added a test for the error case where no break/fallthrough/return
is given.

Closes #754.
2013-01-23 14:41:23 -08:00
Jon Siwek
0a69b87f03 Fix uninitialized locals in event/hook handlers from having a value.
Since values for local variables are referenced by offset within a Frame
(not by identifier name), and event/hook handler bodies share a common
Frame, the value offsets for local variables in different handlers may
overlap.  This meant locals in a handler without an initialization may
actually end up referring to the value of a previous handler's local
that has the same Frame offset.  When executing the body, that can
possibly result in a type-conflict error or give give unexpected
results instead of a "use of uninitialized value" error.

This patch makes it so uninitialized locals do always refer to a null
value before executing the body of a event/hook handler, so that using
them without assigning a value within the body will connsistently give
a "use of uninitialized value" error.

Addresses #932.
2013-01-17 15:21:50 -06:00
Jon Siwek
be71a42f4c Add "fallthrough" keyword, require a flow statement to end case blocks.
Case blocks in switch statements now must end in a break, return, or
fallthrough statement to give best mix of safety, readability, and
flexibility.

The new fallthrough keyword explicitly allows control to be passed to the
next case block in a switch statement.

Addresses #754.
2013-01-16 16:37:50 -06:00
Jon Siwek
8695053e27 Disable automatic case fallthrough in switch stmts. Addresses #754.
Case bodies now don't require a "break" statement to prevent fallthrough
to case bodies below.  Empty case bodies generate an error message at
parse-time to help indicate the absence of automatic fallthrough; to
associate multiple values with a case, use "case 1, 2:" instead of
"case 1: case 2:".
2013-01-11 11:43:15 -06:00
Jon Siwek
8b46bbb1c0 Change substring index notation to use a colon (addresses #422).
String slice notation is written as `s[1:2]` instead of `s[1, 2]`
because the later is ambiguous with composite index types.
2013-01-07 13:29:05 -06:00
Robin Sommer
5e3c286490 Merge remote-tracking branch 'origin/topic/jsiwek/string-indexing'
* origin/topic/jsiwek/string-indexing:
  Add array-style index accessor for strings.  Addresses #422.

Closes #422.
2012-12-20 17:43:26 -08:00
Robin Sommer
037085605c Merge remote-tracking branch 'origin/topic/jsiwek/ticket-923'
* origin/topic/jsiwek/ticket-923:
  Improve error for invalid use of types as values (addresses #923).

Close 923.
2012-12-20 15:21:27 -08:00
Jon Siwek
55c515d50a Add array-style index accessor for strings. Addresses #422.
The index expression can take up to two indices for the start and end
index of the substring to return (e.g. "mystring[1,3]").  Negative
indices are allowed, with -1 representing the last character in the
string.  The indexing is not cyclic -- if the starting index is >= the
length of the string an empty string is returned, and if the ending
index is >= the length of the string then it's interpreted as the last
index of the string.  Assigning to substrings accessed like this isn't
allowed.
2012-12-20 17:13:06 -06:00
Jon Siwek
939a64b73a Finish implementation of script-layer switch statement. Addresses #754.
They behave like C-style switches except case labels can be comprised
of multiple literal constants delimited by commas.  Only atomic types
are allowed for now.  Case label bodies that don't execute a "return"
or "break" statement will fall through to subsequent cases.  A default
case label is allowed.
2012-12-20 12:49:50 -06:00
Jon Siwek
2f0c698ed5 Improve error for invalid use of types as values (addresses #923).
This scripting error can now generate an error message at parse-time
instead of run-time and also includes location information.
2012-12-18 14:31:39 -06:00
Jon Siwek
290c2a0b4d Make const variables actually constant. Addresses #922.
Both local and global variables declared with "const" could be modified,
but now expressions that would modify them should generate an error
message at parse-time.
2012-12-13 15:05:29 -06:00
Jon Siwek
f6d5da423c Fix record constructors in table initializer indices. Addresses #660.
For an index expression list, ListExpr::InitVal() passed the TypeList
to Expr::InitVal() for each expression element in the list instead of
the type for that element.  This made RecordConstructorExpr::InitVal()
complain since it expects a RecordType and not a TypeList with a
RecordType element as an argument.  In most other cases, Expr::InitVal()
worked because check_and_promote() "flattens" the list to a single type.
2012-12-12 14:52:08 -06:00
Jon Siwek
32239ea633 Bad record constructor initializers now give an error (addresses #34).
As opposed to a segfault.
2012-12-04 16:29:23 -06:00
Jon Siwek
75278af8a1 Invalid vector indices now generate error message (addresses #24).
The error/behavior is the same as accessing tables at invalid indices.
2012-12-04 15:22:16 -06:00