-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,34 @@ macro_rules! redis_module { | |
use $crate::configuration::get_bool_default_config_value; | ||
use $crate::configuration::get_enum_default_config_value; | ||
|
||
if ctx.is_null() { | ||
$crate::logging::log_warning( | ||
"The module context pointer is null." | ||
); | ||
return raw::Status::Err as _; | ||
} | ||
|
||
if argv.is_null() && argc != 0 { | ||
$crate::logging::log_warning( | ||
"The module argv is null but the argc is not zero." | ||
); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. You assume here that none NULL argv means that There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I am also not sure if the negative values of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Checking for it now too. |
||
$crate::logging::log_warning( | ||
"The module argv is initialised but has no data." | ||
); | ||
return raw::Status::Err as _; | ||
} | ||
|
||
if !argv.is_null() && unsafe { !(*argv).is_null() } && (argc <= 0) { | ||
$crate::logging::log_warning( | ||
"Incorrect number of module arguments." | ||
); | ||
return raw::Status::Err as _; | ||
} | ||
|
||
// We use a statically sized buffer to avoid allocating. | ||
// This is needed since we use a custom allocator that relies on the Redis allocator, | ||
// which isn't yet ready at this point. | ||
|
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.