-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add checks for module initialisation. #336
base: master
Are you sure you want to change the base?
Conversation
b076313
to
9b8d3dc
Compare
src/macros.rs
Outdated
if ctx.is_null() { | ||
return raw::Status::Err as _; | ||
} | ||
|
||
if argv.is_null() && argc != 0 { | ||
return raw::Status::Err as _; | ||
} | ||
|
||
if !argv.is_null() && unsafe { (*argv).is_null() } { | ||
return raw::Status::Err as _; | ||
} | ||
|
||
if !argv.is_null() && unsafe { !(*argv).is_null() } && (argc.is_negative() || argc == 0) { | ||
return raw::Status::Err as _; | ||
} | ||
|
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.
This can be collapsed into
if ctx.is_null() || (argv.is_null() && argc != 0) || (!argv.is_null() && unsafe { (*argv).is_null() })
|| (!argv.is_null() && unsafe { !(*argv).is_null() } && (argc.is_negative() || argc == 0)) {
return raw::Status::Err as _;
}
But doesn't look good.
@@ -190,6 +190,22 @@ macro_rules! redis_module { | |||
use $crate::configuration::get_bool_default_config_value; | |||
use $crate::configuration::get_enum_default_config_value; | |||
|
|||
if ctx.is_null() { | |||
return raw::Status::Err as _; |
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.
Maybe we should log why we did not start
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.
Log with what? You mean just eprintln!
?
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.
We can log even with NULL context. If we can not log its better to crash with a huge panic here. If this will happened and exit silently we will spend hours trying to guess why the module did not start.
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.
Sure, let's log something then.
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.
Logging now.
return raw::Status::Err as _; | ||
} | ||
|
||
if !argv.is_null() && unsafe { (*argv).is_null() } { |
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.
You assume here that none NULL argv means that argc > 0
. I am not sure this is promise.
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.
Yes, I am also not sure.
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.
I am also not sure if the negative values of argc
are ever allowed.
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.
No, we should not get a negative value.
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.
Checking for it now too.
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.
I think we should also check for pointer alignment, at least for argv.
I disagree it will fix the issue, it might give us a better clue where to search for the issue. The real issue is that we got a NULL or unaligned pointer from Redis. I also suspect it might be related to the sanitiser itself. |
Indeed, it won't ever fix any issues, it will solve the debug assertion and will only allow the correct code though. |
This should resolve the debug assertion and allow only safe code to continue.
This should resolve the debug assertion and allow only safe code to continue.
https://app.circleci.com/pipelines/github/RedisJSON/RedisJSON/6447/workflows/34fa491b-ece8-4dd5-a5ad-3d5c6df9e024/jobs/25181/artifacts