diff --git a/reactos/dll/ntdll/rtl/version.c b/reactos/dll/ntdll/rtl/version.c index 88cadb21d70..e8a39b23ec8 100644 --- a/reactos/dll/ntdll/rtl/version.c +++ b/reactos/dll/ntdll/rtl/version.c @@ -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)) { diff --git a/reactos/ntoskrnl/rtl/misc.c b/reactos/ntoskrnl/rtl/misc.c index f933c57070a..2e9974208d5 100644 --- a/reactos/ntoskrnl/rtl/misc.c +++ b/reactos/ntoskrnl/rtl/misc.c @@ -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)) {