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

Add checks for module initialisation. #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Copy link
Collaborator

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

Copy link
Collaborator Author

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!?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Logging now.

}

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() } {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

$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.
Expand Down