Skip to content

Commit 1ef11cf

Browse files
author
Pavel Kovalenko
committed
Fix crash (buffer overflow) when command line length exceeds 511.
1 parent 3aa65f4 commit 1ef11cf

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/xrCore/xrCore.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
4141
#endif
4242
// Init COM so we can use CoCreateInstance
4343
// HRESULT co_res =
44-
if (!strstr(GetCommandLine(),"-editor"))
44+
Params = xr_strdup(GetCommandLine());
45+
xr_strlwr(Params);
46+
if (!strstr(Params, "-editor"))
4547
CoInitializeEx (NULL, COINIT_MULTITHREADED);
4648

47-
xr_strcpy (Params,sizeof(Params),GetCommandLine());
48-
_strlwr_s (Params,sizeof(Params));
49-
5049
string_path fn,dr,di;
5150

5251
// application path
@@ -147,7 +146,7 @@ void xrCore::_destroy ()
147146
xr_delete (trained_model);
148147
}
149148
#endif
150-
149+
xr_free(Params);
151150
Memory._destroy ();
152151
}
153152
}

src/xrCore/xrCore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class XRCORE_API xrCore
299299
string_path WorkingPath;
300300
string64 UserName;
301301
string64 CompName;
302-
string512 Params;
302+
char* Params;
303303
DWORD dwFrame;
304304

305305
public:

src/xrEngine/x_ray.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,8 +1556,10 @@ void doBenchmark(LPCSTR name)
15561556
xr_strcpy (g_sBenchmarkName, test_name);
15571557

15581558
test_command = ini.r_string_wb("benchmark",test_name);
1559-
xr_strcpy (Core.Params,*test_command);
1560-
_strlwr_s (Core.Params);
1559+
u32 cmdSize = test_command.size()+1;
1560+
Core.Params = (char*)xr_realloc(Core.Params, cmdSize);
1561+
xr_strcpy(Core.Params, cmdSize, test_command.c_str());
1562+
xr_strlwr(Core.Params);
15611563

15621564
InitInput ();
15631565
if(i){

src/xrEngine/xrSASH.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ void xrSASH::LoopNative()
136136
//xr_strcpy(g_sBenchmarkName, test_name);
137137

138138
test_command = ini.r_string_wb("benchmark",test_name);
139-
xr_strcpy( Core.Params, *test_command );
140-
_strlwr_s( Core.Params );
139+
u32 cmdSize = test_command.size()+1;
140+
Core.Params = (char*)xr_realloc(Core.Params, cmdSize);
141+
xr_strcpy(Core.Params, cmdSize, test_command.c_str());
142+
xr_strlwr(Core.Params);
141143

142144
RunBenchmark(test_name);
143145

0 commit comments

Comments
 (0)