Unverified Commit 611c9502 authored by Shockingly Good's avatar Shockingly Good Committed by GitHub
Browse files

Fix crash in RM_GetCurrentUserName() when the user isn't accessible (#13619)

The crash happens whenever the user isn't accessible, for example, it
isn't set for the context (when it is temporary) or in some other cases
like `notifyKeyspaceEvent`. To properly check for the ACL compliance, we
need to get the user name and the user to invoke other APIs. However, it
is not possible if it crashes, and it is impossible to work that around
in the code since we don't know (and **shouldn't know**!) when it is
available and when it is not.
parent 0a8e5469
......@@ -9678,6 +9678,12 @@ RedisModuleString *RM_GetModuleUserACLString(RedisModuleUser *user) {
* The returned string must be released with RedisModule_FreeString() or by
* enabling automatic memory management. */
RedisModuleString *RM_GetCurrentUserName(RedisModuleCtx *ctx) {
/* Sometimes, the user isn't passed along the call stack or isn't
* even set, so we need to check for the members to avoid crashes. */
if (ctx->client == NULL || ctx->client->user == NULL || ctx->client->user->name == NULL) {
return NULL;
}
return RM_CreateString(ctx,ctx->client->user->name,sdslen(ctx->client->user->name));
}
 
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment