summaryrefslogtreecommitdiff
path: root/src/functions.c
diff options
context:
space:
mode:
authorMeir Shpilraien (Spielrein) <meir@redis.com>2021-12-26 08:37:24 +0200
committerGitHub <noreply@github.com>2021-12-26 08:37:24 +0200
commit08ff606b0bf93e5c5e62927cc9dbd229a28ee379 (patch)
treec8ef10cad9aab2f2a3ef9e16b8945ed5f8cd56c1 /src/functions.c
parent63f606d3e3fa8196f98627a1c3924179811d07a1 (diff)
downloadredis-08ff606b0bf93e5c5e62927cc9dbd229a28ee379.tar.gz
Changed fuction name to be case insensitive. (#9984)
Use case insensitive string comparison for function names (like we do for commands and configs) In addition, add verification that the functions only use the following characters: [a-zA-Z0-9_]
Diffstat (limited to 'src/functions.c')
-rw-r--r--src/functions.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/functions.c b/src/functions.c
index aa71c19e3..8da845250 100644
--- a/src/functions.c
+++ b/src/functions.c
@@ -54,10 +54,10 @@ dictType engineDictType = {
};
dictType functionDictType = {
- dictSdsHash, /* hash function */
+ dictSdsCaseHash, /* hash function */
dictSdsDup, /* key dup */
NULL, /* val dup */
- dictSdsKeyCompare, /* key compare */
+ dictSdsKeyCaseCompare,/* key compare */
dictSdsDestructor, /* key destructor */
engineFunctionDispose,/* val destructor */
NULL /* allow to expand */
@@ -438,10 +438,34 @@ NULL };
addReplyHelp(c, help);
}
+/* Verify that the function name is of the format: [a-zA-Z0-9_][a-zA-Z0-9_]? */
+static int functionsVerifyName(sds name) {
+ if (sdslen(name) == 0) {
+ return C_ERR;
+ }
+ for (size_t i = 0 ; i < sdslen(name) ; ++i) {
+ char curr_char = name[i];
+ if ((curr_char >= 'a' && curr_char <= 'z') ||
+ (curr_char >= 'A' && curr_char <= 'Z') ||
+ (curr_char >= '0' && curr_char <= '9') ||
+ (curr_char == '_'))
+ {
+ continue;
+ }
+ return C_ERR;
+ }
+ return C_OK;
+}
+
/* Compile and save the given function, return C_OK on success and C_ERR on failure.
* In case on failure the err out param is set with relevant error message */
int functionsCreateWithFunctionCtx(sds function_name,sds engine_name, sds desc, sds code,
int replace, sds* err, functionsCtx *functions) {
+ if (functionsVerifyName(function_name)) {
+ *err = sdsnew("Function names can only contain letters and numbers and must be at least one character long");
+ return C_ERR;
+ }
+
engineInfo *ei = dictFetchValue(engines, engine_name);
if (!ei) {
*err = sdsnew("Engine not found");