From 1f7facda5b6a589d5d1046b078435821a1766468 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 30 Oct 2014 12:19:25 -0500 Subject: [PATCH] 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"; }; + } + }