Skip to content

Commit

Permalink
Fix potential stack overflow in CEnvironment::load_weathers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kovalenko committed Oct 8, 2014
1 parent 976b434 commit 2055b8d
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 @@ -588,7 +588,7 @@ void CEnvironment::load_weathers ()
typedef xr_vector<LPSTR> file_list_type;
file_list_type* file_list = FS.file_list_open("$game_weathers$","");
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 @@ -598,14 +598,11 @@ void CEnvironment::load_weathers ()
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 = WeatherCycles[identifier];
id.assign(*i, length-4);
EnvVec& env = WeatherCycles[id.c_str()];

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

Expand Down

0 comments on commit 2055b8d

Please sign in to comment.