Skip to content

Commit

Permalink
Fix crash (buffer overflow) when command line length exceeds 511.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kovalenko committed Oct 11, 2014
1 parent 3aa65f4 commit 1ef11cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
#endif
// Init COM so we can use CoCreateInstance
// HRESULT co_res =
if (!strstr(GetCommandLine(),"-editor"))
Params = xr_strdup(GetCommandLine());
xr_strlwr(Params);
if (!strstr(Params, "-editor"))
CoInitializeEx (NULL, COINIT_MULTITHREADED);

xr_strcpy (Params,sizeof(Params),GetCommandLine());
_strlwr_s (Params,sizeof(Params));

string_path fn,dr,di;

// application path
Expand Down Expand Up @@ -147,7 +146,7 @@ void xrCore::_destroy ()
xr_delete (trained_model);
}
#endif

xr_free(Params);
Memory._destroy ();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/xrCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class XRCORE_API xrCore
string_path WorkingPath;
string64 UserName;
string64 CompName;
string512 Params;
char* Params;
DWORD dwFrame;

public:
Expand Down
6 changes: 4 additions & 2 deletions src/xrEngine/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,10 @@ void doBenchmark(LPCSTR name)
xr_strcpy (g_sBenchmarkName, test_name);

test_command = ini.r_string_wb("benchmark",test_name);
xr_strcpy (Core.Params,*test_command);
_strlwr_s (Core.Params);
u32 cmdSize = test_command.size()+1;
Core.Params = (char*)xr_realloc(Core.Params, cmdSize);
xr_strcpy(Core.Params, cmdSize, test_command.c_str());
xr_strlwr(Core.Params);

InitInput ();
if(i){
Expand Down
6 changes: 4 additions & 2 deletions src/xrEngine/xrSASH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ void xrSASH::LoopNative()
//xr_strcpy(g_sBenchmarkName, test_name);

test_command = ini.r_string_wb("benchmark",test_name);
xr_strcpy( Core.Params, *test_command );
_strlwr_s( Core.Params );
u32 cmdSize = test_command.size()+1;
Core.Params = (char*)xr_realloc(Core.Params, cmdSize);
xr_strcpy(Core.Params, cmdSize, test_command.c_str());
xr_strlwr(Core.Params);

RunBenchmark(test_name);

Expand Down

0 comments on commit 1ef11cf

Please sign in to comment.