Skip to content

Commit 7fd5245

Browse files
authored
[GEN][ZH] Fix dereferencing NULL pointer 'ext' in DX8Wrapper::_Create_DX8_Surface() (#1112)
1 parent c8625ae commit 7fd5245

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,9 +2403,10 @@ IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(const char *filename_)
24032403
// If file not found, try the dds format
24042404
// else create a surface with missing texture in it
24052405
char compressed_name[200];
2406-
strncpy(compressed_name,filename_, 200);
2406+
strncpy(compressed_name,filename_, ARRAY_SIZE(compressed_name));
2407+
compressed_name[ARRAY_SIZE(compressed_name)-1] = '\0';
24072408
char *ext = strstr(compressed_name, ".");
2408-
if ( (strlen(ext)==4) &&
2409+
if ( ext && (strlen(ext)==4) &&
24092410
( (ext[1] == 't') || (ext[1] == 'T') ) &&
24102411
( (ext[2] == 'g') || (ext[2] == 'G') ) &&
24112412
( (ext[3] == 'a') || (ext[3] == 'A') ) ) {

GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,9 +2942,10 @@ IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(const char *filename_)
29422942
// If file not found, try the dds format
29432943
// else create a surface with missing texture in it
29442944
char compressed_name[200];
2945-
strncpy(compressed_name,filename_, 200);
2945+
strncpy(compressed_name,filename_, ARRAY_SIZE(compressed_name));
2946+
compressed_name[ARRAY_SIZE(compressed_name)-1] = '\0';
29462947
char *ext = strstr(compressed_name, ".");
2947-
if ( (strlen(ext)==4) &&
2948+
if ( ext && (strlen(ext)==4) &&
29482949
( (ext[1] == 't') || (ext[1] == 'T') ) &&
29492950
( (ext[2] == 'g') || (ext[2] == 'G') ) &&
29502951
( (ext[3] == 'a') || (ext[3] == 'A') ) ) {

0 commit comments

Comments
 (0)