Changeset - r15221:4e305be6015a
[Not reviewed]
master
0 2 0
rubidium - 14 years ago 2010-05-20 15:14:10
rubidium@openttd.org
(svn r19865) -Fix [FS#3830]: crash when changing locale settings from console due to strcpy-ing a string into a pointer
2 files changed with 11 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/settings.cpp
Show inline comments
 
@@ -1710,21 +1710,28 @@ uint GetCompanySettingIndex(const char *
 
}
 

	
 
/**
 
 * Set a setting value with a string.
 
 * @param index the settings index.
 
 * @param value the value to write
 
 * @note CANNOT BE SAVED IN THE SAVEGAME.
 
 * @param force_newgame force the newgame settings
 
 * @note Strings WILL NOT be synced over the network
 
 */
 
bool SetSettingValue(uint index, const char *value)
 
bool SetSettingValue(uint index, const char *value, bool force_newgame)
 
{
 
	const SettingDesc *sd = &_settings[index];
 
	assert(sd->save.conv & SLF_NETWORK_NO);
 

	
 
	if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
 
		char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
 
		free(*var);
 
		*var = strcmp(value, "(null)") == 0 ? NULL : strdup(value);
 
	} else {
 
	char *var = (char*)GetVariableAddress(NULL, &sd->save);
 
	ttd_strlcpy(var, value, sd->save.length);
 
	}
 
	if (sd->desc.proc != NULL) sd->desc.proc(0);
 

	
 
	return true;
 
}
 

	
 
/**
 
@@ -1775,13 +1782,13 @@ void IConsoleSetSetting(const char *name
 
		IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
 
		return;
 
	}
 

	
 
	bool success;
 
	if (sd->desc.cmd == SDT_STRING) {
 
		success = SetSettingValue(index, value);
 
		success = SetSettingValue(index, value, force_newgame);
 
	} else {
 
		uint32 val;
 
		extern bool GetArgumentInteger(uint32 *value, const char *arg);
 
		success = GetArgumentInteger(&val, value);
 
		if (!success) {
 
			IConsolePrintF(CC_ERROR, "'%s' is not an integer.", value);
src/settings_internal.h
Show inline comments
 
@@ -83,12 +83,12 @@ struct SettingDesc {
 
 * and save->variable has its address, otherwise save->variable only holds the
 
 * offset in a certain struct */
 
typedef SettingDesc SettingDescGlobVarList;
 

	
 
const SettingDesc *GetSettingFromName(const char *name, uint *i);
 
bool SetSettingValue(uint index, int32 value, bool force_newgame = false);
 
bool SetSettingValue(uint index, const char *value);
 
bool SetSettingValue(uint index, const char *value, bool force_newgame = false);
 
void SetCompanySetting(uint index, int32 value);
 

	
 
extern VehicleDefaultSettings _old_vds;
 

	
 
#endif /* SETTINGS_H */
0 comments (0 inline, 0 general)