Skip to content

Commit 8ddddb8

Browse files
AssetMgr: Add SEH protection against accessing freed prototype pointers
1 parent 1c181d6 commit 8ddddb8

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,18 @@ PrototypeClass * WW3DAssetManager::Find_Prototype(const char * name)
17011701
PrototypeClass * test = PrototypeHashTable[hash];
17021702

17031703
while (test != NULL) {
1704-
if (stricmp(test->Get_Name(),name) == 0) {
1705-
return test;
1704+
// Defensive check: protect against accessing freed/invalid prototype pointers
1705+
// Use SEH to catch access violations from dangling pointers in the hash chain
1706+
__try {
1707+
const char* test_name = test->Get_Name();
1708+
if (test_name != NULL && stricmp(test_name, name) == 0) {
1709+
return test;
1710+
}
1711+
}
1712+
__except(EXCEPTION_EXECUTE_HANDLER) {
1713+
// Invalid pointer detected (use-after-free), stop traversing the chain
1714+
// This can happen if a prototype was deleted without being properly removed from the hash table
1715+
break;
17061716
}
17071717
test = test->friend_getNextHash();
17081718
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,18 @@ PrototypeClass * WW3DAssetManager::Find_Prototype(const char * name)
16781678
PrototypeClass * test = PrototypeHashTable[hash];
16791679

16801680
while (test != NULL) {
1681-
if (stricmp(test->Get_Name(),name) == 0) {
1682-
return test;
1681+
// Defensive check: protect against accessing freed/invalid prototype pointers
1682+
// Use SEH to catch access violations from dangling pointers in the hash chain
1683+
__try {
1684+
const char* test_name = test->Get_Name();
1685+
if (test_name != NULL && stricmp(test_name, name) == 0) {
1686+
return test;
1687+
}
1688+
}
1689+
__except(EXCEPTION_EXECUTE_HANDLER) {
1690+
// Invalid pointer detected (use-after-free), stop traversing the chain
1691+
// This can happen if a prototype was deleted without being properly removed from the hash table
1692+
break;
16831693
}
16841694
test = test->friend_getNextHash();
16851695
}

0 commit comments

Comments
 (0)