Permalink
Browse files

Corrected script commands containing arrays (#3932)

* Corrects a potential map-server crash with script commands min, max, getpartymember, getguildmember, getunits, getmapunits, getareaunits, getunitdata, and channel_setgroup when a character variable is used when no character is attached to the script.
Thanks to @Tokeiburu and @Atemo!
  • Loading branch information...
aleos89 committed Feb 11, 2019
1 parent c5a5c54 commit d649ede46b3e9f4b68105b04080d9d3b3817f1c6
Showing with 40 additions and 0 deletions.
  1. +40 −0 src/map/script.cpp
@@ -8269,6 +8269,14 @@ BUILDIN_FUNC(getpartymember)
ShowError("buildin_getpartymember: The array %s is not string type.\n", varname);
return SCRIPT_CMD_FAILURE;
}
if (not_server_variable(*varname)) {
struct map_session_data *sd;

if (!script_rid2sd(sd)) {
ShowError("buildin_getpartymember: Cannot use a player variable '%s' if no player is attached.\n", varname);
return SCRIPT_CMD_FAILURE;
}
}
}

for (i = 0; i < MAX_PARTY; i++) {
@@ -11164,6 +11172,11 @@ BUILDIN_FUNC(getunits)
id = reference_getid(data);
idx = reference_getindex(data);
name = reference_getname(data);

if (not_server_variable(*name) && !script_rid2sd(sd)) {
ShowError("buildin_%s: Cannot use a player variable '%s' if no player is attached.\n", command, name);
return SCRIPT_CMD_FAILURE;
}
}

for (bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter))
@@ -17334,6 +17347,11 @@ BUILDIN_FUNC(getunitdata)

name = reference_getname(data);

if (not_server_variable(*name) && !script_rid2sd(sd)) {
ShowError("buildin_getunitdata: Cannot use a player variable '%s' if no player is attached.\n", name);
return SCRIPT_CMD_FAILURE;
}

#define getunitdata_sub(idx__,var__) setd_sub(st,sd,name,(idx__),(void *)__64BPRTSIZE((int)(var__)),data->ref)

switch(bl->type) {
ShowError("buildin_getguildmember: The array %s is not string type.\n", varname);
return SCRIPT_CMD_FAILURE;
}
if (not_server_variable(*varname)) {
struct map_session_data *sd;

if (!script_rid2sd(sd)) {
ShowError("buildin_getguildmember: Cannot use a player variable '%s' if no player is attached.\n", varname);
return SCRIPT_CMD_FAILURE;
}
}
}

for (i = 0; i < MAX_GUILD; i++) {
// Get the session data, if a player is attached
sd = st->rid ? map_id2sd(st->rid) : NULL;

if (not_server_variable(*name) && !script_rid2sd(sd)) {
ShowError("buildin_%s: Cannot use a player variable '%s' if no player is attached.\n", functionname, name);
return SCRIPT_CMD_FAILURE;
}

// Try to find the array's source pointer
if( !script_array_src( st, sd, name, reference_getref( data ) ) ){
ShowError( "buildin_%s: not a array!\n", functionname );
return SCRIPT_CMD_FAILURE;
}

if (not_server_variable(*varname)) {
struct map_session_data *sd;

if (!script_rid2sd(sd)) {
ShowError("buildin_%s: Cannot use a player variable '%s' if no player is attached.\n", funcname, varname);
return SCRIPT_CMD_FAILURE;
}
}

n = script_array_highest_key(st, NULL, reference_getname(data), reference_getref(data));
if (n < 1) {
ShowError("buildin_channel_setgroup: No group id listed.\n");

0 comments on commit d649ede

Please sign in to comment.