Skip to content

Commit

Permalink
EVALSHA is now case insensitive.
Browse files Browse the repository at this point in the history
EVALSHA used to crash if the SHA1 was not lowercase (Issue #783).
Fixed using a case insensitive dictionary type for the sha -> script
map used for replication of scripts.
  • Loading branch information
antirez committed Nov 22, 2012
1 parent cceb0c5 commit 95f68f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ int dictSdsKeyCompare(void *privdata, const void *key1,
return memcmp(key1, key2, l1) == 0;
}

/* A case insensitive version used for the command lookup table. */
/* A case insensitive version used for the command lookup table and other
* places where case insensitive non binary-safe comparison is needed. */
int dictSdsKeyCaseCompare(void *privdata, const void *key1,
const void *key2)
{
Expand Down Expand Up @@ -508,6 +509,16 @@ dictType dbDictType = {
dictRedisObjectDestructor /* val destructor */
};

/* server.lua_scripts sha (as sds string) -> scripts (as robj) cache. */
dictType shaScriptObjectDictType = {
dictSdsCaseHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictSdsKeyCaseCompare, /* key compare */
dictSdsDestructor, /* key destructor */
dictRedisObjectDestructor /* val destructor */
};

/* Db->expires */
dictType keyptrDictType = {
dictSdsHash, /* hash function */
Expand Down
1 change: 1 addition & 0 deletions src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ extern dictType setDictType;
extern dictType zsetDictType;
extern dictType clusterNodesDictType;
extern dictType dbDictType;
extern dictType shaScriptObjectDictType;
extern double R_Zero, R_PosInf, R_NegInf, R_Nan;
extern dictType hashDictType;

Expand Down
2 changes: 1 addition & 1 deletion src/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void scriptingInit(void) {
/* Initialize a dictionary we use to map SHAs to scripts.
* This is useful for replication, as we need to replicate EVALSHA
* as EVAL, so we need to remember the associated script. */
server.lua_scripts = dictCreate(&dbDictType,NULL);
server.lua_scripts = dictCreate(&shaScriptObjectDictType,NULL);

/* Register the redis commands table and fields */
lua_newtable(lua);
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/scripting.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ start_server {tags {"scripting"}} {
r evalsha 9bd632c7d33e571e9f24556ebed26c3479a87129 0
} {myval}

test {EVALSHA - Can we call a SHA1 in uppercase?} {
r evalsha 9BD632C7D33E571E9F24556EBED26C3479A87129 0
} {myval}

test {EVALSHA - Do we get an error on invalid SHA1?} {
catch {r evalsha NotValidShaSUM 0} e
set _ $e
Expand Down

0 comments on commit 95f68f7

Please sign in to comment.