Skip to content

Commit

Permalink
Fix potential stack overflow in CEnvironment::load_weather_effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kovalenko committed Oct 8, 2014
1 parent 2055b8d commit c611d5f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/xrEngine/Environment_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ void CEnvironment::load_weather_effects ()
typedef xr_vector<LPSTR> file_list_type;
file_list_type* file_list = FS.file_list_open("$game_weather_effects$","");
VERIFY (file_list);

xr_string id;
file_list_type::const_iterator i = file_list->begin();
file_list_type::const_iterator e = file_list->end();
for ( ; i != e; ++i) {
Expand All @@ -652,14 +652,11 @@ void CEnvironment::load_weather_effects ()
VERIFY ((*i)[length - 3] == 'l');
VERIFY ((*i)[length - 2] == 't');
VERIFY ((*i)[length - 1] == 'x');
u32 new_length = length - 4;
LPSTR identifier = (LPSTR)_alloca((new_length + 1)*sizeof(char));
Memory.mem_copy (identifier, *i, new_length*sizeof(char));
identifier[new_length] = 0;
EnvVec& env = WeatherFXs[identifier];
id.assign(*i, length-4);
EnvVec& env = WeatherFXs[id.c_str()];

string_path file_name;
FS.update_path (file_name, "$game_weather_effects$", identifier);
FS.update_path (file_name, "$game_weather_effects$", id.c_str());
xr_strcat (file_name, ".ltx");
CInifile* config = CInifile::Create(file_name);

Expand Down

0 comments on commit c611d5f

Please sign in to comment.