-
Notifications
You must be signed in to change notification settings - Fork 7
Add null check for pointer-based function arguments #37
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
base: master
Are you sure you want to change the base?
Add null check for pointer-based function arguments #37
Conversation
Hmm, this fix breaks the zeek
|
bif_arg.cc
Outdated
// For pointer types, validate that the return value is valid to avoid accessing null pointers. | ||
std::string_view c_type{builtin_func_arg_type[type].c_type}; | ||
if ( c_type.back() == '*' ) { | ||
fprintf(fp, "\t if ( %s == nullptr ) {\n", name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that be better than before line 60, where we already would access a nullptr - runtime_type_check is only true for variable args, so maybe the combination doesn't really happen right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are definitely places where the second one can get generated without the first one. I added a null check on the first one plus a flag for whether it got generated to avoid generating it twice.
6a89435
to
2e352c7
Compare
The btest failure is actually interesting, and might negate this approach to fixing this bug entirely. The
Note that it already has a check for an invalid connection at the bottom and reports a weird for that. The null checks that were added by this PR's change supersede that check, return an error, and cause the function to return a nullptr when it wouldn't have before. |
2e352c7
to
eb5ab3d
Compare
Fixes #33
This adds a simple check for bif function arguments that map to pointer types. Unfortunately due to the generic-ness of the types defined in
include/bif_type.def
, the only real way to determine if it's a pointer is to check if the type string ends with*
.