Skip to content

Commit 2055b8d

Browse files
author
Pavel Kovalenko
committed
Fix potential stack overflow in CEnvironment::load_weathers.
1 parent 976b434 commit 2055b8d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/xrEngine/Environment_misc.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void CEnvironment::load_weathers ()
588588
typedef xr_vector<LPSTR> file_list_type;
589589
file_list_type* file_list = FS.file_list_open("$game_weathers$","");
590590
VERIFY (file_list);
591-
591+
xr_string id;
592592
file_list_type::const_iterator i = file_list->begin();
593593
file_list_type::const_iterator e = file_list->end();
594594
for ( ; i != e; ++i) {
@@ -598,14 +598,11 @@ void CEnvironment::load_weathers ()
598598
VERIFY ((*i)[length - 3] == 'l');
599599
VERIFY ((*i)[length - 2] == 't');
600600
VERIFY ((*i)[length - 1] == 'x');
601-
u32 new_length = length - 4;
602-
LPSTR identifier = (LPSTR)_alloca((new_length + 1)*sizeof(char));
603-
Memory.mem_copy (identifier, *i, new_length*sizeof(char));
604-
identifier[new_length] = 0;
605-
EnvVec& env = WeatherCycles[identifier];
601+
id.assign(*i, length-4);
602+
EnvVec& env = WeatherCycles[id.c_str()];
606603

607604
string_path file_name;
608-
FS.update_path (file_name, "$game_weathers$", identifier);
605+
FS.update_path (file_name, "$game_weathers$", id.c_str());
609606
xr_strcat (file_name, ".ltx");
610607
CInifile* config = CInifile::Create(file_name);
611608

0 commit comments

Comments
 (0)