mirror of
https://github.com/reactos/reactos.git
synced 2024-11-07 15:10:53 +00:00
- Fix weird code in RtlGetVersion (inspired by Coverity ID 1355 and Daniel's patch in bug 3906).
See issue #3906 for more details. svn path=/trunk/; revision=37638
This commit is contained in:
parent
af008eee80
commit
e9b31b7fdf
2 changed files with 25 additions and 18 deletions
|
@ -104,6 +104,8 @@ RtlGetNtVersionNumbers(LPDWORD major, LPDWORD minor, LPDWORD build)
|
|||
NTSTATUS NTAPI
|
||||
RtlGetVersion(RTL_OSVERSIONINFOW *Info)
|
||||
{
|
||||
ULONG i, MaxLength;
|
||||
|
||||
if (Info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOW) ||
|
||||
Info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
|
||||
{
|
||||
|
@ -113,17 +115,19 @@ RtlGetVersion(RTL_OSVERSIONINFOW *Info)
|
|||
Info->dwMinorVersion = Peb->OSMinorVersion;
|
||||
Info->dwBuildNumber = Peb->OSBuildNumber;
|
||||
Info->dwPlatformId = Peb->OSPlatformId;
|
||||
RtlZeroMemory(Info->szCSDVersion, sizeof(Info->szCSDVersion));
|
||||
if(((Peb->OSCSDVersion >> 8) & 0xFF) != 0)
|
||||
{
|
||||
int i = _snwprintf(Info->szCSDVersion,
|
||||
(sizeof(Info->szCSDVersion) / sizeof(Info->szCSDVersion[0])) - 1,
|
||||
L"Service Pack %d",
|
||||
((Peb->OSCSDVersion >> 8) & 0xFF));
|
||||
Info->szCSDVersion[i] = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
RtlZeroMemory(Info->szCSDVersion, sizeof(Info->szCSDVersion));
|
||||
MaxLength = (sizeof(Info->szCSDVersion) / sizeof(Info->szCSDVersion[0])) - 1;
|
||||
i = _snwprintf(Info->szCSDVersion,
|
||||
MaxLength,
|
||||
L"Service Pack %d",
|
||||
((Peb->OSCSDVersion >> 8) & 0xFF));
|
||||
if (i < 0)
|
||||
{
|
||||
/* null-terminate if it was overflowed */
|
||||
Info->szCSDVersion[MaxLength] = L'\0';
|
||||
}
|
||||
}
|
||||
if (Info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@ RtlGetNtGlobalFlags(VOID)
|
|||
NTSTATUS STDCALL
|
||||
RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
|
||||
{
|
||||
ULONG i, MaxLength;
|
||||
if (lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOW) ||
|
||||
lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
|
||||
{
|
||||
|
@ -46,17 +47,19 @@ RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
|
|||
lpVersionInformation->dwMinorVersion = NtMinorVersion;
|
||||
lpVersionInformation->dwBuildNumber = NtBuildNumber;
|
||||
lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
|
||||
RtlZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion));
|
||||
if(((CmNtCSDVersion >> 8) & 0xFF) != 0)
|
||||
{
|
||||
int i = _snwprintf(lpVersionInformation->szCSDVersion,
|
||||
(sizeof(lpVersionInformation->szCSDVersion) / sizeof(lpVersionInformation->szCSDVersion[0])) - 1,
|
||||
L"Service Pack %d",
|
||||
((CmNtCSDVersion >> 8) & 0xFF));
|
||||
lpVersionInformation->szCSDVersion[i] = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
RtlZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion));
|
||||
MaxLength = (sizeof(lpVersionInformation->szCSDVersion) / sizeof(lpVersionInformation->szCSDVersion[0])) - 1;
|
||||
i = _snwprintf(lpVersionInformation->szCSDVersion,
|
||||
MaxLength,
|
||||
L"Service Pack %d",
|
||||
((CmNtCSDVersion >> 8) & 0xFF));
|
||||
if (i < 0)
|
||||
{
|
||||
/* null-terminate if it was overflowed */
|
||||
lpVersionInformation->szCSDVersion[MaxLength] = L'\0';
|
||||
}
|
||||
}
|
||||
if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue