From: Ari Johnson Date: Wed, 21 Feb 2007 00:53:35 +0000 (+0000) Subject: Relaxed restrictions on function and command names X-Git-Tag: 0.73~153 X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=99b463071bc51c17644b75c3ed4b47cde2891ada;p=cobramush.git Relaxed restrictions on function and command names --- diff --git a/hdrs/externs.h b/hdrs/externs.h index 408a4b8..27bea38 100644 --- a/hdrs/externs.h +++ b/hdrs/externs.h @@ -358,6 +358,7 @@ extern int get_current_quota(dbref who); extern void change_quota(dbref who, int payment); extern int ok_name(const char *name); extern int ok_command_name(const char *name); +extern int ok_function_name(const char *name); extern int ok_player_name(const char *name, dbref player, dbref thing); extern int ok_player_alias(const char *alias, dbref player, dbref thing); extern int ok_password(const char *password); diff --git a/src/funmisc.c b/src/funmisc.c index bb317fe..e858d4f 100644 --- a/src/funmisc.c +++ b/src/funmisc.c @@ -60,7 +60,7 @@ FUNCTION(fun_valid) else if (!strcasecmp(args[0], "command")) safe_boolean(ok_command_name(upcasestr(args[1])), buff, bp); else if (!strcasecmp(args[0], "function")) - safe_boolean(ok_command_name(upcasestr(args[1])), buff, bp); + safe_boolean(ok_function_name(upcasestr(args[1])), buff, bp); else safe_str("#-1", buff, bp); } diff --git a/src/predicat.c b/src/predicat.c index 5e66ba6..993f33d 100644 --- a/src/predicat.c +++ b/src/predicat.c @@ -882,9 +882,10 @@ ok_password(const char *password) return 1; } -/** Is a name ok for a command or function? - * It must begin with an uppercase alpha, and contain only - * uppercase alpha, numbers, or underscore thereafter. +/** Is a name ok for a command? + * It must contain only uppercase alpha, numbers, or punctuation. + * It must contain at least one uppercase alpha. + * It may not begin with " : ; & ] \ and # (the special tokens). * \param name name to check. * \retval 1 name is acceptable. * \retval 0 name is not acceptable. @@ -893,17 +894,80 @@ int ok_command_name(const char *name) { const unsigned char *p; - if (!isupper((unsigned char) *name)) + int cnt = 0; + /* First char: uppercase alphanum or legal punctuation */ + switch ((unsigned char) *name) { + case SAY_TOKEN: + case POSE_TOKEN: + case SEMI_POSE_TOKEN: + case EMIT_TOKEN: + case NOEVAL_TOKEN: + case NUMBER_TOKEN: + case '&': return 0; + default: + if (!isupper((unsigned char) *name) && !isdigit((unsigned char) *name)) + return 0; + } + /* Everything else must be printable and non-space, and we need + * to find at least one uppercase alpha + */ for (p = (unsigned char *) name; p && *p; p++) { - if (!(isupper(*p) || isdigit(*p) || (*p == '_'))) + if (isspace(*p)) return 0; + if (isupper(*p)) + cnt++; } - + if (!cnt) + return 0; /* Not too long */ if (strlen(name) >= COMMAND_NAME_LIMIT) return 0; + return 1; +} +/** Is a name ok for a function? + * It must start with uppercase alpha or punctuation and may contain only + * uppercase alpha, numbers, or punctuation thereafter. + * It must contain at least one uppercase alpha. + * It may not begin with " : ; & ] \ and # (the special tokens). + * \param name name to check. + * \retval 1 name is acceptable. + * \retval 0 name is not acceptable. + */ +int +ok_function_name(const char *name) +{ + const unsigned char *p; + int cnt = 0; + /* First char: uppercase alpha or legal punctuation */ + switch ((unsigned char) *name) { + case SAY_TOKEN: + case POSE_TOKEN: + case SEMI_POSE_TOKEN: + case EMIT_TOKEN: + case NOEVAL_TOKEN: + case NUMBER_TOKEN: + case '&': + return 0; + default: + if (!isupper((unsigned char) *name)) + return 0; + } + /* Everything else must be printable and non-space, and we need + * to find at least one uppercase alpha + */ + for (p = (unsigned char *) name; p && *p; p++) { + if (isspace(*p)) + return 0; + if (isupper(*p)) + cnt++; + } + if (!cnt) + return 0; + /* Not too long */ + if (strlen(name) >= COMMAND_NAME_LIMIT) + return 0; return 1; }