summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadelyn Olson <matolson@amazon.com>2019-11-06 08:25:07 +0000
committerMadelyn Olson <matolson@amazon.com>2019-11-06 08:25:07 +0000
commit05292e342f95c8e191e4fa85011e39372660cfec (patch)
tree037ba066d14766732fcd6c506940b61093c6bea2
parent75d977145e8b2a046df17bec582d910492b1d0ba (diff)
downloadredis-05292e342f95c8e191e4fa85011e39372660cfec.tar.gz
Improved some error handling in examples
-rw-r--r--src/module.c4
-rw-r--r--src/modules/helloacl.c6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/module.c b/src/module.c
index 17fca5e1d..5517a9f59 100644
--- a/src/module.c
+++ b/src/module.c
@@ -5216,7 +5216,7 @@ RedisModuleUser *RM_CreateModuleUser(const char *name) {
RedisModuleUser *new_user = zmalloc(sizeof(RedisModuleUser));
new_user->user = ACLCreateUnlinkedUser();
- /* Free the previous temporarily assigned name to assign the new one */
+ /* Free the temporarily assigned name to assign the new one */
sdsfree(new_user->user->name);
new_user->user->name = sdsnew(name);
return new_user;
@@ -5262,6 +5262,8 @@ RedisModuleAuthCtx *RM_CreateAuthCtx(RedisModuleUserChangedFunc callback, void *
RedisModuleAuthCtx *auth_ctx = zmalloc(sizeof(RedisModuleAuthCtx));
auth_ctx->callback = callback;
auth_ctx->privdata = privdata;
+ auth_ctx->module = NULL;
+ auth_ctx->authenticated_client = NULL;
return auth_ctx;
}
diff --git a/src/modules/helloacl.c b/src/modules/helloacl.c
index 95dcb09c8..cf4819082 100644
--- a/src/modules/helloacl.c
+++ b/src/modules/helloacl.c
@@ -92,7 +92,11 @@ int AuthGlobalCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
}
RedisModuleAuthCtx *auth_ctx = RedisModule_CreateAuthCtx(HelloACL_UserChanged, NULL);
- RedisModule_AuthClientWithUser(ctx, global, auth_ctx);
+ if (RedisModule_AuthClientWithUser(ctx, global, auth_ctx) ==
+ REDISMODULE_ERR) {
+ return RedisModule_ReplyWithError(ctx, "Couldn't authenticate client");
+ }
+
global_auth_ctx = auth_ctx;
return RedisModule_ReplyWithSimpleString(ctx, "OK");