From 13f18d2b17b577bfc9b0d28397cb7be3bb291b90 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 3 Aug 2016 18:09:36 +0200 Subject: [PATCH] Modules: handle NULL replies more gracefully. After all crashing at every API misuse makes everybody's life more complex. --- src/module.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/module.c b/src/module.c index 03bee27b..e0bc417d 100644 --- a/src/module.c +++ b/src/module.c @@ -762,6 +762,11 @@ void RM_RetainString(RedisModuleCtx *ctx, RedisModuleString *str) { * and length of the string. The returned pointer and length should only * be used for read only accesses and never modified. */ const char *RM_StringPtrLen(const RedisModuleString *str, size_t *len) { + if (str == NULL) { + const char *errmsg = "(NULL string reply referenced in module)"; + if (len) *len = strlen(errmsg); + return errmsg; + } if (len) *len = sdslen(str->ptr); return str->ptr; } @@ -2203,6 +2208,7 @@ void RM_FreeCallReply(RedisModuleCallReply *reply) { /* Return the reply type. */ int RM_CallReplyType(RedisModuleCallReply *reply) { + if (!reply) return REDISMODULE_REPLY_UNKNOWN; return reply->type; }