Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve &expire_func compatibility type-checking #1505

Merged
merged 2 commits into from Apr 16, 2021

Conversation

jsiwek
Copy link
Contributor

@jsiwek jsiwek commented Apr 12, 2021

Fixes GH-1503

Previously, incompatible &expire_funcs could mistakenly be used, such as
when using that attribute on the unspecified table()/set()
initializations/assignments, resulting in invalid function calls that
eventually crash Zeek.

Ideally, type-checking could catch this at parse-time always, but found that may not generally be possible and a run-time type-check may have to happen in rare scenarios (but the common ones still always catch parse-time). Going from common to rare:

  • When using unspecified table() expression in initializations, the full type/attribute info isn't available to be caught in the previous CheckAttr() location, have to wait for make_var logic to propagate from unspecified table() -> ID -> TableVal ctor -> TableVal::SetAttrs()

  • If using unspecified table() in run-time assignment, the TableCoerceExpr could likely be expanded to help catch more at parse-time, but eventually it will use TableVal ctor -> TableVal::SetAttrs()

  • The TableVal::SetAttrs() method is technically there for anyone to call directly (e.g. external plugins).

So this patch addresses the common denominator: TableVal::SetAttrs() must not be allowed to set an incompatible expire function.

It's possible that some checks are now redundant and can give multiple error messages for the same issue, but I find that to be ok: don't want to get rid of the Attributes::CheckAttr() check, because I'm not sure if it's still helping find some types incompatible expire functions at parse-time rather than run-time (e.g. when full type info actually is available for assignments).

Previously, incompatible &expire_funcs could mistakenly be used, such as
when using that attribute on the unspecified table()/set()
initializations/assignments, resulting in invalid function calls that
eventually crash Zeek.
@jsiwek jsiwek added Type: Bug 🐛 Unexpected behavior or output. Area: Scripting labels Apr 12, 2021
@jsiwek jsiwek added this to the 4.1.0 milestone Apr 12, 2021
@jsiwek jsiwek added this to Unassigned / Todo in Release 4.1.0 via automation Apr 12, 2021
Copy link
Contributor

@timwoj timwoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question re: the btest, but otherwise looks fine to me. Feel free to merge it after resolving that.

testing/btest/language/expire-func-type-check.zeek Outdated Show resolved Hide resolved
@jsiwek jsiwek self-assigned this Apr 15, 2021
Now covers more forms of both valid and invalid &expire_funcs
@jsiwek jsiwek merged commit df9b571 into master Apr 16, 2021
Release 4.1.0 automation moved this from Unassigned / Todo to Done Apr 16, 2021
@0xxon 0xxon deleted the topic/jsiwek/gh-1503-improve-expire-func-type-check branch July 13, 2022 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Scripting Type: Bug 🐛 Unexpected behavior or output.
Projects
No open projects
Release 4.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

Segfault in 4.0.0 - internal error: bad reference count [2]
2 participants