* Fix #2425 Character variable lengths and char-server Medium term fox for crash on char-serv caused by too long character variable. Add few error msg and safety. Add npc/test/npc_test_longvar.txt as a basic test. NB: The config.in for max_colum size if not really set as best would either retrive that value from sql, or use the same config file to actually set the sql column size... May be handle later with some kind of hibernate ORM. Thanks to @Tokeiburu, @aleos89, @Lemongrass3110.
This commit is contained in:
@@ -405,6 +405,7 @@ int intif_saveregistry(struct map_session_data *sd)
|
||||
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
|
||||
const char *varname = NULL;
|
||||
struct script_reg_state *src = NULL;
|
||||
bool lValid = false;
|
||||
|
||||
if( data->type != DB_DATA_PTR ) // it's a @number
|
||||
continue;
|
||||
@@ -420,13 +421,17 @@ int intif_saveregistry(struct map_session_data *sd)
|
||||
continue;
|
||||
|
||||
src->update = false;
|
||||
lValid = script_check_RegistryVariableLength(0,varname,&len);
|
||||
++len;
|
||||
|
||||
len = strlen(varname)+1;
|
||||
|
||||
if (!lValid) { //this is sql colum size, must be retrive from config
|
||||
ShowError("intif_saveregistry: Variable name length is too long (aid: %d, cid: %d): '%s' sz=%d\n", sd->status.account_id, sd->status.char_id, varname, len);
|
||||
continue;
|
||||
}
|
||||
WFIFOB(inter_fd, plen) = (unsigned char)len; // won't be higher; the column size is 32
|
||||
plen += 1;
|
||||
|
||||
safestrncpy(WFIFOCP(inter_fd,plen), varname, len);
|
||||
safestrncpy(WFIFOCP(inter_fd,plen), varname, len); //the key
|
||||
plen += len;
|
||||
|
||||
WFIFOL(inter_fd, plen) = script_getvaridx(key.i64);
|
||||
@@ -435,13 +440,19 @@ int intif_saveregistry(struct map_session_data *sd)
|
||||
if( src->type ) {
|
||||
struct script_reg_str *p = (struct script_reg_str *)src;
|
||||
|
||||
WFIFOB(inter_fd, plen) = p->value ? 2 : 3;
|
||||
WFIFOB(inter_fd, plen) = p->value ? 2 : 3; //var type
|
||||
plen += 1;
|
||||
|
||||
if( p->value ) {
|
||||
len = strlen(p->value)+1;
|
||||
lValid = script_check_RegistryVariableLength(1,p->value,&len);
|
||||
++len;
|
||||
if ( !lValid ) { // error can't be higher; the column size is 254. (nb the transmission limit with be fixed with protobuf revamp)
|
||||
ShowDebug( "intif_saveregistry: Variable value length is too long (aid: %d, cid: %d): '%s' sz=%d to be saved with current system and will be truncated\n",sd->status.account_id, sd->status.char_id,p->value,len);
|
||||
len = 254;
|
||||
p->value[len - 1] = '\0'; //this is backward for old char-serv but new one doesn't need this
|
||||
}
|
||||
|
||||
WFIFOB(inter_fd, plen) = (unsigned char)len; // won't be higher; the column size is 254
|
||||
WFIFOB(inter_fd, plen) = len;
|
||||
plen += 1;
|
||||
|
||||
safestrncpy(WFIFOCP(inter_fd,plen), p->value, len);
|
||||
@@ -3666,7 +3677,7 @@ int intif_parse_clan_onlinecount( int fd ){
|
||||
* @return
|
||||
* 0 (unknow packet).
|
||||
* 1 sucess (no error)
|
||||
* 2 invalid lenght of packet (not enough data yet)
|
||||
* 2 invalid length of packet (not enough data yet)
|
||||
*/
|
||||
int intif_parse(int fd)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user