Skip to content

Commit 7f4c703

Browse files
authored
[GEN][ZH] Fix uninitialized memory access in Get_OS_Info (TheSuperHackers#438)
1 parent 1370428 commit 7f4c703

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

Generals/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,14 @@ void Get_OS_Info(
12651265
unsigned build_minor=(OSVersionBuildNumber&0xff0000)>>16;
12661266
unsigned build_sub=(OSVersionBuildNumber&0xffff);
12671267

1268+
// TheSuperHackers @bugfix JAJames 17/03/2025 Fix uninitialized memory access and add more Windows versions.
1269+
memset(&os_info,0,sizeof(os_info));
1270+
os_info.Code="UNKNOWN";
1271+
os_info.SubCode="UNKNOWN";
1272+
os_info.VersionString="UNKNOWN";
1273+
12681274
switch (OSVersionPlatformId) {
12691275
default:
1270-
memset(&os_info,0,sizeof(os_info));
1271-
os_info.Code="UNKNOWN";
1272-
os_info.SubCode="UNKNOWN";
1273-
os_info.VersionString="UNKNOWN";
12741276
break;
12751277
case VER_PLATFORM_WIN32_WINDOWS:
12761278
{
@@ -1325,8 +1327,33 @@ void Get_OS_Info(
13251327
os_info.Code="WINXP";
13261328
return;
13271329
}
1328-
os_info.Code="WINXX";
1330+
}
1331+
if (OSVersionNumberMajor==6) {
1332+
if (OSVersionNumberMinor==0) {
1333+
os_info.Code="WINVS"; // Vista
1334+
return;
1335+
}
1336+
if (OSVersionNumberMinor==1) {
1337+
os_info.Code="WIN70"; // Win 7
1338+
return;
1339+
}
1340+
if (OSVersionNumberMinor==2) {
1341+
os_info.Code="WIN80"; // Win 8.0
1342+
return;
1343+
}
1344+
if (OSVersionNumberMinor==3) {
1345+
os_info.Code="WIN81"; // Win 8.1
1346+
return;
1347+
}
1348+
}
1349+
if (OSVersionNumberMinor==10) {
1350+
os_info.Code="WIN1X"; // Win 10, Win 11, Server 2016, Server 2019, Server 2022
13291351
return;
13301352
}
1353+
// Reference 1: https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoa#remarks
1354+
// Reference 2: https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version
1355+
1356+
// No more-specific version detected; fallback to XX
1357+
os_info.Code="WINXX";
13311358
}
13321359
}

GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/cpudetect.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,14 @@ void Get_OS_Info(
12651265
unsigned build_minor=(OSVersionBuildNumber&0xff0000)>>16;
12661266
unsigned build_sub=(OSVersionBuildNumber&0xffff);
12671267

1268+
// TheSuperHackers @bugfix JAJames 17/03/2025 Fix uninitialized memory access and add more Windows versions.
1269+
memset(&os_info,0,sizeof(os_info));
1270+
os_info.Code="UNKNOWN";
1271+
os_info.SubCode="UNKNOWN";
1272+
os_info.VersionString="UNKNOWN";
1273+
12681274
switch (OSVersionPlatformId) {
12691275
default:
1270-
memset(&os_info,0,sizeof(os_info));
1271-
os_info.Code="UNKNOWN";
1272-
os_info.SubCode="UNKNOWN";
1273-
os_info.VersionString="UNKNOWN";
12741276
break;
12751277
case VER_PLATFORM_WIN32_WINDOWS:
12761278
{
@@ -1325,8 +1327,33 @@ void Get_OS_Info(
13251327
os_info.Code="WINXP";
13261328
return;
13271329
}
1328-
os_info.Code="WINXX";
1330+
}
1331+
if (OSVersionNumberMajor==6) {
1332+
if (OSVersionNumberMinor==0) {
1333+
os_info.Code="WINVS"; // Vista
1334+
return;
1335+
}
1336+
if (OSVersionNumberMinor==1) {
1337+
os_info.Code="WIN70"; // Win 7
1338+
return;
1339+
}
1340+
if (OSVersionNumberMinor==2) {
1341+
os_info.Code="WIN80"; // Win 8.0
1342+
return;
1343+
}
1344+
if (OSVersionNumberMinor==3) {
1345+
os_info.Code="WIN81"; // Win 8.1
1346+
return;
1347+
}
1348+
}
1349+
if (OSVersionNumberMinor==10) {
1350+
os_info.Code="WIN1X"; // Win 10, Win 11, Server 2016, Server 2019, Server 2022
13291351
return;
13301352
}
1353+
// Reference 1: https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoa#remarks
1354+
// Reference 2: https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version
1355+
1356+
// No more-specific version detected; fallback to XX
1357+
os_info.Code="WINXX";
13311358
}
13321359
}

0 commit comments

Comments
 (0)