From 2d96b603bbc8d348a8d3cdba471669f13dfcc93c Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Mon, 22 May 2023 18:04:42 +0200 Subject: [PATCH] Add checks for the module initialisation. This should resolve the debug assertion and allow only safe code to continue. --- src/macros.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index a0b429eb..c4bbf878 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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() } { + $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.