From e5f75cde9340c203744d6808554ac64f6a289079 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 28 Oct 2014 14:21:16 -0500 Subject: [PATCH 1/5] BIT-1280: Fix checking vector indices via "in". $ cat test.bro local vec: vector of string = { "zero" }; vec[2] = "two"; print 0 in vec, 1 in vec, 2 in vec; $ bro -b test.bro T, F, T --- src/Expr.cc | 12 +++++++++--- .../Baseline/language.vector-in-operator/out | 11 +++++++++++ testing/btest/language/vector-in-operator.bro | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 testing/btest/Baseline/language.vector-in-operator/out create mode 100644 testing/btest/language/vector-in-operator.bro diff --git a/src/Expr.cc b/src/Expr.cc index 4a29c11cb5..c7ea906865 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -636,7 +636,7 @@ Val* BinaryExpr::Eval(Frame* f) const return v_result; } - if ( is_vec1 || is_vec2 ) + if ( IsVector(Type()->Tag()) && (is_vec1 || is_vec2) ) { // fold vector against scalar VectorVal* vv = (is_vec1 ? v1 : v2)->AsVectorVal(); VectorVal* v_result = new VectorVal(Type()->AsVectorType()); @@ -4703,8 +4703,14 @@ Val* InExpr::Fold(Val* v1, Val* v2) const v2->Type()->Tag() == TYPE_SUBNET ) return new Val(v2->AsSubNetVal()->Contains(v1->AsAddr()), TYPE_BOOL); - TableVal* vt = v2->AsTableVal(); - if ( vt->Lookup(v1, false) ) + Val* res; + + if ( is_vector(v2) ) + res = v2->AsVectorVal()->Lookup(v1); + else + res = v2->AsTableVal()->Lookup(v1, false); + + if ( res ) return new Val(1, TYPE_BOOL); else return new Val(0, TYPE_BOOL); diff --git a/testing/btest/Baseline/language.vector-in-operator/out b/testing/btest/Baseline/language.vector-in-operator/out new file mode 100644 index 0000000000..5d4600a188 --- /dev/null +++ b/testing/btest/Baseline/language.vector-in-operator/out @@ -0,0 +1,11 @@ +[zero, one, , , , five, , seven] +vec[0] = zero.exe +vec[1] = one.exe +vec[2] = +vec[3] = +vec[4] = +vec[5] = five.exe +vec[6] = +vec[7] = seven.exe +vec[8] = +vec[9] = diff --git a/testing/btest/language/vector-in-operator.bro b/testing/btest/language/vector-in-operator.bro new file mode 100644 index 0000000000..5936145363 --- /dev/null +++ b/testing/btest/language/vector-in-operator.bro @@ -0,0 +1,17 @@ +# @TEST-EXEC: bro -b %INPUT >out +# @TEST-EXEC: btest-diff out + +local ten = "0123456789"; +local vec: vector of string = { "zero", "one" }; +local n = 0; +vec[5] = "five"; +vec[7] = "seven"; +print vec; +vec = vec + ".exe"; + +for ( c in ten ) + { + local is_set: bool = (n in vec); + print fmt("vec[%s] = %s", n, is_set ? vec[n] : ""); + ++n; + } From 1f7facda5b6a589d5d1046b078435821a1766468 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 30 Oct 2014 12:19:25 -0500 Subject: [PATCH 2/5] Fix segfault if when statement's RHS is unitialized. If it is ever assigned a value, the body of the when can be triggered as usual. Addresses BIT-1176. --- src/Trigger.cc | 2 +- .../language.when-unitialized-rhs/out | 38 +++++++++++++++++++ .../btest/language/when-unitialized-rhs.bro | 32 ++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 testing/btest/Baseline/language.when-unitialized-rhs/out create mode 100644 testing/btest/language/when-unitialized-rhs.bro diff --git a/src/Trigger.cc b/src/Trigger.cc index ed5d0e18f6..c2ca9aeb6b 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -206,7 +206,7 @@ bool Trigger::Eval() return false; } - if ( v->IsZero() ) + if ( ! v || v->IsZero() ) { // Not true. Perhaps next time... DBG_LOG(DBG_NOTIFIERS, "%s: trigger condition is false", Name()); diff --git a/testing/btest/Baseline/language.when-unitialized-rhs/out b/testing/btest/Baseline/language.when-unitialized-rhs/out new file mode 100644 index 0000000000..620b384da2 --- /dev/null +++ b/testing/btest/Baseline/language.when-unitialized-rhs/out @@ -0,0 +1,38 @@ +error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.when-unitialized-rhs/when-unitialized-rhs.bro, line 9: value used but not set (crashMe) +error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.when-unitialized-rhs/when-unitialized-rhs.bro, line 14: value used but not set (x) +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +2nd when stmt executing, 999 +1st when stmt executing, not anymore you don't +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 diff --git a/testing/btest/language/when-unitialized-rhs.bro b/testing/btest/language/when-unitialized-rhs.bro new file mode 100644 index 0000000000..21b94c6e02 --- /dev/null +++ b/testing/btest/language/when-unitialized-rhs.bro @@ -0,0 +1,32 @@ +# @TEST-EXEC: bro -b -r $TRACES/wikipedia.trace %INPUT >out 2>&1 +# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out + +global crashMe: function(): string; +global x: int; + +event bro_init() + { + when( local result = crashMe() ) + { + print "1st when stmt executing", result; + } + + when( local other_result = x ) + { + print "2nd when stmt executing", other_result; + } + } + +global conn_count = 0; + +event new_connection(c: connection) + { + ++conn_count; + print conn_count; + + if ( conn_count == 10 ) + { + x = 999; + crashMe = function(): string { return "not anymore you don't"; }; + } + } From 5ef6dd0e3c68d01561fbd6566653f8b0a139ad0d Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Fri, 31 Oct 2014 17:44:58 -0700 Subject: [PATCH 3/5] Adding call to new binpac::init() function. --- aux/binpac | 2 +- src/main.cc | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/aux/binpac b/aux/binpac index 3a4684801a..3c80db8b56 160000 --- a/aux/binpac +++ b/aux/binpac @@ -1 +1 @@ -Subproject commit 3a4684801aafa0558383199e9abd711650b53af9 +Subproject commit 3c80db8b5697c7b95e1d0d48ce01b625cf70c5a1 diff --git a/src/main.cc b/src/main.cc index 63949c5093..15aea3d3fe 100644 --- a/src/main.cc +++ b/src/main.cc @@ -775,6 +775,9 @@ int main(int argc, char** argv) // DEBUG_MSG("HMAC key: %s\n", md5_digest_print(shared_hmac_md5_key)); init_hash_function(); + // Must come after hash initialization. + binpac::init(); + ERR_load_crypto_strings(); OPENSSL_add_all_algorithms_conf(); SSL_library_init(); From 395f06d93caa9729018d8bd31d7049d63c772e1f Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Fri, 31 Oct 2014 17:45:25 -0700 Subject: [PATCH 4/5] Updating submodule(s). [nomail] --- CHANGES | 4 ++++ VERSION | 2 +- aux/binpac | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 47bf14c0de..3109d4670e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +2.3-274 | 2014-10-31 17:45:25 -0700 + + * Adding call to new binpac::init() function. (Robin Sommer) + 2.3-272 | 2014-10-31 16:29:42 -0700 * Fix segfault if when statement's RHS is unitialized. Addresses diff --git a/VERSION b/VERSION index 88a48cd475..a11a6bac50 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3-272 +2.3-274 diff --git a/aux/binpac b/aux/binpac index 3c80db8b56..3a4684801a 160000 --- a/aux/binpac +++ b/aux/binpac @@ -1 +1 @@ -Subproject commit 3c80db8b5697c7b95e1d0d48ce01b625cf70c5a1 +Subproject commit 3a4684801aafa0558383199e9abd711650b53af9 From e0d9adc9c9098ba1ead88adb98c52dc431d80688 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Fri, 31 Oct 2014 17:49:02 -0700 Subject: [PATCH 5/5] Updating submodule(s). [nomail] --- aux/binpac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aux/binpac b/aux/binpac index 3a4684801a..7f440d060e 160000 --- a/aux/binpac +++ b/aux/binpac @@ -1 +1 @@ -Subproject commit 3a4684801aafa0558383199e9abd711650b53af9 +Subproject commit 7f440d060e0df675c1aab3357ff7b93fcf1c2cae