diff options
author | AnnieRuru <jeankof@ymail.com> | 2015-11-16 01:04:55 +0800 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-12-22 04:11:51 +0100 |
commit | feff016d6bc7e811d03c958da754df20f630b33b (patch) | |
tree | e16b5eb79113536d37a54fa2ceb3f6236472d053 | |
parent | c276e2a6aa566400b1026236e7b2c09bfdcb72b5 (diff) | |
download | hercules-feff016d6bc7e811d03c958da754df20f630b33b.tar.gz hercules-feff016d6bc7e811d03c958da754df20f630b33b.tar.bz2 hercules-feff016d6bc7e811d03c958da754df20f630b33b.tar.xz hercules-feff016d6bc7e811d03c958da754df20f630b33b.zip |
Throw error when variable name length too long
-rw-r--r-- | doc/script_commands.txt | 3 | ||||
-rw-r--r-- | src/map/script.c | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt index ef4816889..c08596f9a 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -525,7 +525,8 @@ If a variable was never set, it is considered to equal zero for integer variables or an empty string ("", nothing between the quotes) for string variables. Once you set it to that, the variable is as good as forgotten forever, and no trace remains of it even if it was stored with character -or account data. +or account data. The maximum length of variable name including prefix and +suffix is 32. Some variables are special, that is, they are already defined for you by the scripting engine. You can see the full list somewhere in diff --git a/src/map/script.c b/src/map/script.c index 7a5292159..829555820 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2726,6 +2726,13 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) { prefix = name[0]; postfix = name[strlen(name) - 1]; + if (strlen(name) > SCRIPT_VARNAME_LENGTH) { + ShowError("script_get_val: variable name too long. '%s'\n", name); + script->reportsrc(st); + st->state = END; + return data; + } + //##TODO use reference_tovariable(data) when it's confirmed that it works [FlavioJS] if( !reference_toconstant(data) && not_server_variable(prefix) ) { sd = script->rid2sd(st); @@ -3142,6 +3149,13 @@ void set_reg_instance_num(struct script_state* st, int64 num, const char* name, int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct reg_db *ref) { char prefix = name[0]; + if (strlen(name) > SCRIPT_VARNAME_LENGTH) { + ShowError("script:set_reg: variable name too long. '%s'\n", name); + script->reportsrc(st); + st->state = END; + return 0; + } + if( is_string_variable(name) ) {// string variable const char *str = (const char*)value; |