Skip to content

Commit c611d5f

Browse files
author
Pavel Kovalenko
committed
Fix potential stack overflow in CEnvironment::load_weather_effects.
1 parent 2055b8d commit c611d5f

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
@@ -642,7 +642,7 @@ void CEnvironment::load_weather_effects ()
642642
typedef xr_vector<LPSTR> file_list_type;
643643
file_list_type* file_list = FS.file_list_open("$game_weather_effects$","");
644644
VERIFY (file_list);
645-
645+
xr_string id;
646646
file_list_type::const_iterator i = file_list->begin();
647647
file_list_type::const_iterator e = file_list->end();
648648
for ( ; i != e; ++i) {
@@ -652,14 +652,11 @@ void CEnvironment::load_weather_effects ()
652652
VERIFY ((*i)[length - 3] == 'l');
653653
VERIFY ((*i)[length - 2] == 't');
654654
VERIFY ((*i)[length - 1] == 'x');
655-
u32 new_length = length - 4;
656-
LPSTR identifier = (LPSTR)_alloca((new_length + 1)*sizeof(char));
657-
Memory.mem_copy (identifier, *i, new_length*sizeof(char));
658-
identifier[new_length] = 0;
659-
EnvVec& env = WeatherFXs[identifier];
655+
id.assign(*i, length-4);
656+
EnvVec& env = WeatherFXs[id.c_str()];
660657

661658
string_path file_name;
662-
FS.update_path (file_name, "$game_weather_effects$", identifier);
659+
FS.update_path (file_name, "$game_weather_effects$", id.c_str());
663660
xr_strcat (file_name, ".ltx");
664661
CInifile* config = CInifile::Create(file_name);
665662

0 commit comments

Comments
 (0)