Merge remote-tracking branch 'origin/topic/jsiwek/gh-822-ubsan-ci'

* origin/topic/jsiwek/gh-822-ubsan-ci:
  Fix negative-value-left-shift undefined behavior in patricia trie
  Improve negation of ConstExpr
  Avoid signed integer overflow when combining SMB header PID bits
  Avoid unary negation of INT64_MIN in modp_litoa10
  Avoid double-to-int conversion overflows in modp_dtoa functions
  Fix divide-by-zero in Entropy analyzer
  Fix divide-by-zero in stats/profiling memory usage calculation
  Fix uninitialized field in POP3 fuzzer
  Add framework for running UndefinedBehaviorSanitizer in CI
This commit is contained in:
Jon Siwek 2020-09-24 08:16:45 -07:00
commit 8feca7291b
15 changed files with 256 additions and 86 deletions

View file

@ -336,6 +336,36 @@ expr:
{
zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::NegExpr({zeek::AdoptRef{}, $2});
if ( ! $$->IsError() && $2->IsConst() )
{
auto v = $2->ExprVal();
auto tag = v->GetType()->Tag();
if ( tag == zeek::TYPE_COUNT )
{
auto c = v->AsCount();
uint64_t int_max = static_cast<uint64_t>(INT64_MAX) + 1;
if ( c <= int_max )
{
auto ce = new zeek::detail::ConstExpr(zeek::val_mgr->Int(-c));
Unref($$);
$$ = ce;
}
else
{
$$->Error("literal is outside range of 'int' values");
$$->SetError();
}
}
else
{
auto ce = new zeek::detail::ConstExpr($$->Eval(nullptr));
Unref($$);
$$ = ce;
}
}
}
| '+' expr %prec '!'