From e6f83028f63121991c326c8168ebcbf28ab6de97 Mon Sep 17 00:00:00 2001 From: frosch Date: Thu, 2 Jan 2014 17:55:57 +0000 Subject: [PATCH] (svn r26206) -Fix [FS#5829]: Run everything from ini, obg, obs, obs, ... files through str_validate. --- src/ini_load.cpp | 5 +++++ src/table/gameopt_settings.ini | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ini_load.cpp b/src/ini_load.cpp index 6a20873038..158ffa6a78 100644 --- a/src/ini_load.cpp +++ b/src/ini_load.cpp @@ -26,6 +26,8 @@ IniItem::IniItem(IniGroup *parent, const char *name, size_t len) : next(NULL), v if (len == 0) len = strlen(name); this->name = strndup(name, len); + if (this->name != NULL) str_validate(this->name, this->name + len); + *parent->last_item = this; parent->last_item = &this->next; } @@ -61,6 +63,8 @@ IniGroup::IniGroup(IniLoadFile *parent, const char *name, size_t len) : next(NUL if (len == 0) len = strlen(name); this->name = strndup(name, len); + if (this->name != NULL) str_validate(this->name, this->name + len); + this->last_item = &this->item; *parent->last_group = this; parent->last_group = &this->next; @@ -305,6 +309,7 @@ void IniLoadFile::LoadFromDisk(const char *filename, Subdirectory subdir) /* If the value was not quoted and empty, it must be NULL */ item->value = (!quoted && e == t) ? NULL : strndup(t, e - t); + if (item->value != NULL) str_validate(item->value, item->value + strlen(item->value)); } else { /* it's an orphan item */ this->ReportFileError("ini: '", buffer, "' outside of group"); diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini index baf7c35423..3a47c09e33 100644 --- a/src/table/gameopt_settings.ini +++ b/src/table/gameopt_settings.ini @@ -29,15 +29,15 @@ static const char *_settings_profiles = "easy|medium|hard"; static const char *_news_display = "off|summarized|full"; static const SettingDesc _gameopt_settings[] = { - /* In version 4 a new difficulty setting has been added to the difficulty settings, - * town attitude towards demolishing. Needs special handling because some dimwit thought - * it funny to have the GameDifficulty struct be an array while it is a struct of - * same-sized members - * XXX - To save file-space and since values are never bigger than about 10? only - * save the first 16 bits in the savegame. Question is why the values are still int32 - * and why not byte for example? - * 'SLE_FILE_I16 | SLE_VAR_U16' in "diff_custom" is needed to get around SlArray() hack - * for savegames version 0 - though it is an array, it has to go through the byteswap process */ +/* In version 4 a new difficulty setting has been added to the difficulty settings, + * town attitude towards demolishing. Needs special handling because some dimwit thought + * it funny to have the GameDifficulty struct be an array while it is a struct of + * same-sized members + * XXX - To save file-space and since values are never bigger than about 10? only + * save the first 16 bits in the savegame. Question is why the values are still int32 + * and why not byte for example? + * 'SLE_FILE_I16 | SLE_VAR_U16' in "diff_custom" is needed to get around SlArray() hack + * for savegames version 0 - though it is an array, it has to go through the byteswap process */ [post-amble] }; [templates]