[REACTOS] Fix a number of MSVC warnings
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Tue, 29 Jun 2021 16:50:15 +0000 (18:50 +0200)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 23 Jul 2021 20:03:48 +0000 (22:03 +0200)
43 files changed:
base/applications/sndvol32/dialog.c
base/services/wkssvc/wkssvc.c
base/setup/lib/utils/osdetect.c
base/setup/lib/utils/regutil.c
base/setup/usetup/cmdcons.c
base/setup/usetup/mui.c
base/setup/usetup/progress.c
base/setup/usetup/spapisup/cabinet.c
base/setup/usetup/usetup.c
base/shell/cmd/cmdinput.c
base/system/services/config.c
dll/win32/aclui/sidcache.c
dll/win32/advapi32/misc/hwprofiles.c
dll/win32/advapi32/reg/reg.c
dll/win32/kernel32/client/vdm.c
dll/win32/lsasrv/lookup.c
dll/win32/lsasrv/privileges.c
dll/win32/msgina/gui.c
dll/win32/msv1_0/msv1_0.c
dll/win32/msv1_0/precomp.h
dll/win32/ntmarta/ntmarta.c
dll/win32/shell32/CShellLink.cpp
dll/win32/shell32/folders/CPrinterFolder.cpp
dll/win32/syssetup/security.c
drivers/filesystems/fastfat_new/fatstruc.h
drivers/filesystems/npfs/main.c
drivers/input/kbdclass/kbdclass.c
drivers/input/mouclass/mouclass.c
drivers/storage/floppy/floppy/ioctl.c
modules/rosapps/applications/explorer-old/shell/ntobjfs.cpp
modules/rosapps/applications/fraginator/Unfrag.cpp
modules/rosapps/applications/net/netreg/netreg.cpp
modules/rosapps/applications/net/roshttpd/include/httpd.h
modules/rosapps/applications/notevil/notevil.c
modules/rosapps/applications/screensavers/cylfrac/cylfrac.c
modules/rostests/apitests/atl/SubclassWindow.cpp
sdk/include/ddk/acpiioct.h
sdk/include/psdk/intsafe.h
sdk/lib/crt/string/wtoi64.c
sdk/lib/drivers/ip/network/loopback.c
subsystems/mvdm/ntvdm/dos/dem.c
win32ss/printing/providers/localspl/tools.c
win32ss/user/user32/windows/class.c

index 1fac34d..71f1e8a 100644 (file)
@@ -338,7 +338,7 @@ LoadDialog(
     LPWORD Offset;
     WORD FontSize;
     WCHAR FontName[100];
-    WORD Length;
+    SIZE_T Length;
     int width;
 
     DWORD units = GetDialogBaseUnits();
index d1e5b87..6147213 100644 (file)
@@ -73,7 +73,8 @@ static
 DWORD
 ServiceInit(VOID)
 {
-    LSA_STRING ProcessName, PackageName;
+    LSA_STRING ProcessName = RTL_CONSTANT_STRING("Workstation");
+    LSA_STRING PackageName = RTL_CONSTANT_STRING(MSV1_0_PACKAGE_NAME);
     LSA_OPERATIONAL_MODE Mode;
     HANDLE hThread;
     NTSTATUS Status;
@@ -84,10 +85,6 @@ ServiceInit(VOID)
     VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
     GetVersionExW(&VersionInfo);
 
-    ProcessName.Buffer = "Workstation";
-    ProcessName.Length = strlen(ProcessName.Buffer);
-    ProcessName.MaximumLength = ProcessName.Length + 1;
-
     Status = LsaRegisterLogonProcess(&ProcessName,
                                      &LsaHandle,
                                      &Mode);
@@ -97,10 +94,6 @@ ServiceInit(VOID)
         return 1;
     }
 
-    PackageName.Buffer = MSV1_0_PACKAGE_NAME;
-    PackageName.Length = strlen(PackageName.Buffer);
-    PackageName.MaximumLength = PackageName.Length + 1;
-
     Status = LsaLookupAuthenticationPackage(LsaHandle,
                                             &PackageName,
                                             &LsaAuthenticationPackage);
index d191c58..0ee246c 100644 (file)
@@ -320,7 +320,7 @@ CheckForValidPEAndVendor(
 
             RtlStringCbCopyNW(VendorName->Buffer, VendorName->MaximumLength,
                               pvData, BufLen * sizeof(WCHAR));
-            VendorName->Length = wcslen(VendorName->Buffer) * sizeof(WCHAR);
+            VendorName->Length = (USHORT)wcslen(VendorName->Buffer) * sizeof(WCHAR);
 
             Success = TRUE;
         }
index 60e0e9f..012acc0 100644 (file)
@@ -78,7 +78,7 @@ CreateNestedKey(PHANDLE KeyHandle,
             break;
         }
         *Ptr = (WCHAR)0;
-        LocalKeyName.Length = wcslen(LocalKeyName.Buffer) * sizeof(WCHAR);
+        LocalKeyName.Length = (Ptr - LocalKeyName.Buffer) * sizeof(WCHAR);
 
         Status = NtCreateKey(&LocalKeyHandle,
                              KEY_CREATE_SUB_KEY,
@@ -110,7 +110,7 @@ CreateNestedKey(PHANDLE KeyHandle,
         NtClose(LocalKeyHandle);
 
         LocalKeyName.Buffer[LocalKeyName.Length / sizeof(WCHAR)] = L'\\';
-        LocalKeyName.Length = wcslen(LocalKeyName.Buffer) * sizeof(WCHAR);
+        LocalKeyName.Length = (USHORT)wcslen(LocalKeyName.Buffer) * sizeof(WCHAR);
 
         Status = NtCreateKey(&LocalKeyHandle,
                              KEY_ALL_ACCESS,
index 0307c11..e1cd5c7 100644 (file)
@@ -1026,7 +1026,7 @@ ReadCommand(
             {
                 /* If this character insertion will cause screen scrolling,
                  * adjust the saved origin of the command prompt. */
-                tempscreen = strlen(str + current) + curx;
+                tempscreen = (USHORT)strlen(str + current) + curx;
                 if ((tempscreen % State->maxx) == (State->maxx - 1) &&
                     (tempscreen / State->maxx) + cury == (State->maxy - 1))
                 {
index d1e6599..365576e 100644 (file)
@@ -140,7 +140,7 @@ MUIClearPage(
         CONSOLE_ClearStyledText(entry[index].X,
                                 entry[index].Y,
                                 entry[index].Flags,
-                                strlen(entry[index].Buffer));
+                                (USHORT)strlen(entry[index].Buffer));
         index++;
     }
 }
@@ -347,7 +347,7 @@ MUIClearText(
         CONSOLE_ClearTextXY(
             entry[Index].X,
             entry[Index].Y,
-            (ULONG)strlen(entry[Index].Buffer));
+            (USHORT)strlen(entry[Index].Buffer));
 
         /* Increment the index and loop over next entires with the same ID */
         Index++;
@@ -404,7 +404,7 @@ MUIClearStyledText(
             entry[Index].X,
             entry[Index].Y,
             Flags,
-            (ULONG)strlen(entry[Index].Buffer));
+            (USHORT)strlen(entry[Index].Buffer));
 
         /* Increment the index and loop over next entires with the same ID */
         Index++;
index 1d095ae..aa1f81d 100644 (file)
@@ -240,7 +240,7 @@ DrawProgressBar(
     if (Bar->UpdateProgressProc &&
         Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer)))
     {
-        coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
+        coPos.X = Bar->Left + (Bar->Width - (USHORT)strlen(TextBuffer) + 1) / 2;
         coPos.Y = Bar->Top;
         WriteConsoleOutputCharacterA(StdOutput,
                                      TextBuffer,
@@ -383,7 +383,7 @@ ProgressSetStep(
     if (Bar->UpdateProgressProc &&
         Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer)))
     {
-        coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
+        coPos.X = Bar->Left + (Bar->Width - (USHORT)strlen(TextBuffer) + 1) / 2;
         coPos.Y = Bar->Top;
         WriteConsoleOutputCharacterA(StdOutput,
                                      TextBuffer,
index 46ae4e5..c9efdbc 100644 (file)
@@ -981,6 +981,7 @@ CabinetExtractFile(
     PCFFOLDER CurrentFolder;
     LARGE_INTEGER MaxDestFileSize;
     LONG InputLength, OutputLength;
+    SIZE_T StringLength;
     char Chunk[512];
 
     if (wcscmp(Search->Cabinet, CabinetContext->CabinetName) != 0)
@@ -1039,8 +1040,9 @@ CabinetExtractFile(
     {
         RtlInitAnsiString(&AnsiString, Search->File->FileName);
         wcscpy(DestName, CabinetContext->DestPath);
-        UnicodeString.MaximumLength = sizeof(DestName) - wcslen(DestName) * sizeof(WCHAR);
-        UnicodeString.Buffer = DestName + wcslen(DestName);
+        StringLength = wcslen(DestName);
+        UnicodeString.MaximumLength = sizeof(DestName) - (USHORT)StringLength * sizeof(WCHAR);
+        UnicodeString.Buffer = DestName + StringLength;
         UnicodeString.Length = 0;
         RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, FALSE);
 
index 520b257..16a520c 100644 (file)
@@ -1907,7 +1907,7 @@ ShowPartitionSizeInputBox(SHORT Left,
     coPos.X = Left + 2;
     coPos.Y = Top + 2;
     strcpy(Buffer, MUIGetString(STRING_PARTITIONSIZE));
-    iLeft = coPos.X + strlen(Buffer) + 1;
+    iLeft = coPos.X + (USHORT)strlen(Buffer) + 1;
     iTop = coPos.Y;
 
     WriteConsoleOutputCharacterA(StdOutput,
index e609c5a..e1c7c16 100644 (file)
@@ -96,7 +96,7 @@
  *    30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
  *        Fixed problems when the screen was scrolled away.
  *
- *    28-September-2007 (Hervé Poussineau)
+ *    28-September-2007 (Hervé Poussineau)
  *        Added history possibilities to right key.
  */
 
@@ -142,7 +142,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
     SHORT orgy;
     SHORT curx;     /*current x/y cursor position*/
     SHORT cury;
-    SHORT tempscreen;
+    SIZE_T tempscreen;
     INT   count;    /*used in some for loops*/
     INT   current = 0;  /*the position of the cursor in the string (str)*/
     INT   charcount = 0;/*chars in the string (str)*/
index db1b0da..ce97635 100644 (file)
@@ -476,9 +476,16 @@ ScmSetServicePassword(
     UNICODE_STRING Password;
     NTSTATUS Status;
     DWORD dwError = ERROR_SUCCESS;
+    SIZE_T ServiceNameLength;
 
     RtlZeroMemory(&ObjectAttributes, sizeof(OBJECT_ATTRIBUTES));
 
+    ServiceNameLength = wcslen(pszServiceName);
+    if (ServiceNameLength > (UNICODE_STRING_MAX_CHARS - 4))
+    {
+        return ERROR_INVALID_PARAMETER;
+    }
+
     Status = LsaOpenPolicy(NULL,
                            &ObjectAttributes,
                            POLICY_CREATE_SECRET,
@@ -486,7 +493,7 @@ ScmSetServicePassword(
     if (!NT_SUCCESS(Status))
         return RtlNtStatusToDosError(Status);
 
-    ServiceName.Length = (wcslen(pszServiceName) + 4) * sizeof(WCHAR);
+    ServiceName.Length = ((USHORT)ServiceNameLength + 4) * sizeof(WCHAR);
     ServiceName.MaximumLength = ServiceName.Length + sizeof(WCHAR);
     ServiceName.Buffer = HeapAlloc(GetProcessHeap(),
                                    HEAP_ZERO_MEMORY,
index e68cf93..1c9c726 100644 (file)
@@ -176,11 +176,18 @@ OpenLSAPolicyHandle(IN LPWSTR SystemName,
     LSA_OBJECT_ATTRIBUTES LsaObjectAttributes = {0};
     LSA_UNICODE_STRING LsaSystemName, *psn;
     NTSTATUS Status;
+    SIZE_T NameLength;
 
     if (SystemName != NULL && SystemName[0] != L'\0')
     {
+        NameLength = wcslen(SystemName);
+        if (NameLength > UNICODE_STRING_MAX_CHARS)
+        {
+            return FALSE;
+        }
+
         LsaSystemName.Buffer = SystemName;
-        LsaSystemName.Length = wcslen(SystemName) * sizeof(WCHAR);
+        LsaSystemName.Length = NameLength * sizeof(WCHAR);
         LsaSystemName.MaximumLength = LsaSystemName.Length + sizeof(WCHAR);
         psn = &LsaSystemName;
     }
index 980001d..88a0188 100644 (file)
@@ -42,8 +42,8 @@ GetCurrentHwProfileA(LPHW_PROFILE_INFOA lpHwProfileInfo)
     lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo;
 
     /* Convert the profile GUID to ANSI */
-    StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid;
-    StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR);
+    StringU.Buffer = ProfileInfo.szHwProfileGuid;
+    StringU.Length = (USHORT)wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR);
     StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
     StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid;
     StringA.Length = 0;
@@ -58,8 +58,8 @@ GetCurrentHwProfileA(LPHW_PROFILE_INFOA lpHwProfileInfo)
     }
 
     /* Convert the profile name to ANSI */
-    StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName;
-    StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR);
+    StringU.Buffer = ProfileInfo.szHwProfileName;
+    StringU.Length = (USHORT)wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR);
     StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR);
     StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName;
     StringA.Length = 0;
index 36aa3b8..3d739fb 100644 (file)
@@ -961,7 +961,7 @@ CreateNestedKey(PHKEY KeyHandle,
         }
 
         *Ptr = (WCHAR)0;
-        LocalKeyName.Length = wcslen(LocalKeyName.Buffer) * sizeof(WCHAR);
+        LocalKeyName.Length = (USHORT)wcslen(LocalKeyName.Buffer) * sizeof(WCHAR);
 
         Status = NtCreateKey(&LocalKeyHandle,
                              KEY_CREATE_SUB_KEY,
index ff6e785..07022d8 100644 (file)
@@ -105,7 +105,7 @@ BaseCheckVDM(IN ULONG BinaryType,
     PWCHAR CurrentDir = NULL;
     PWCHAR ShortAppName = NULL;
     PWCHAR ShortCurrentDir = NULL;
-    ULONG Length;
+    SIZE_T Length;
     PCHAR AnsiCmdLine = NULL;
     PCHAR AnsiAppName = NULL;
     PCHAR AnsiCurDirectory = NULL;
@@ -283,16 +283,24 @@ BaseCheckVDM(IN ULONG BinaryType,
         goto Cleanup;
     }
 
+    /* Make sure that the command line isn't too long */
+    Length = wcslen(CommandLine);
+    if (Length > UNICODE_STRING_MAX_CHARS - 1)
+    {
+        Status = STATUS_INVALID_PARAMETER;
+        goto Cleanup;
+    }
+
     /* Setup the input parameters */
     CheckVdm->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
     CheckVdm->BinaryType = BinaryType;
     CheckVdm->CodePage = CP_ACP;
     CheckVdm->dwCreationFlags = CreationFlags;
     CheckVdm->CurDrive = CurrentDirectory[0] - L'A';
-    CheckVdm->CmdLen = wcslen(CommandLine) + 1;
-    CheckVdm->AppLen = wcslen(ShortAppName) + 1;
+    CheckVdm->CmdLen = (USHORT)Length + 1;
+    CheckVdm->AppLen = (USHORT)wcslen(ShortAppName) + 1;
     CheckVdm->PifLen = 0; // TODO: PIF file support!
-    CheckVdm->CurDirectoryLen = wcslen(ShortCurrentDir) + 1;
+    CheckVdm->CurDirectoryLen = (USHORT)wcslen(ShortCurrentDir) + 1;
     CheckVdm->EnvLen = AnsiEnvironment->Length;
     CheckVdm->DesktopLen = (StartupInfo->lpDesktop != NULL) ? (wcslen(StartupInfo->lpDesktop) + 1) : 0;
     CheckVdm->TitleLen = (StartupInfo->lpTitle != NULL) ? (wcslen(StartupInfo->lpTitle) + 1) : 0;
index f593f2b..7d39169 100644 (file)
@@ -96,9 +96,18 @@ LsapCreateSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
               PSID *SidPtr)
 {
     PWELL_KNOWN_SID SidEntry;
+    SIZE_T AccountNameLength, DomainNameLength;
     PULONG p;
     ULONG i;
 
+    AccountNameLength = wcslen(AccountName);
+    DomainNameLength = wcslen(DomainName);
+    if ((AccountNameLength > UNICODE_STRING_MAX_CHARS) ||
+        (DomainNameLength > UNICODE_STRING_MAX_CHARS))
+    {
+        return FALSE;
+    }
+
     SidEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WELL_KNOWN_SID));
     if (SidEntry == NULL)
         return FALSE;
@@ -126,7 +135,7 @@ LsapCreateSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
 
 //    RtlInitUnicodeString(&SidEntry->AccountName,
 //                         AccountName);
-    SidEntry->AccountName.Length = wcslen(AccountName) * sizeof(WCHAR);
+    SidEntry->AccountName.Length = (USHORT)AccountNameLength * sizeof(WCHAR);
     SidEntry->AccountName.MaximumLength = SidEntry->AccountName.Length + sizeof(WCHAR);
     SidEntry->AccountName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
                                                    SidEntry->AccountName.MaximumLength);
@@ -142,7 +151,7 @@ LsapCreateSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
 
 //    RtlInitUnicodeString(&SidEntry->DomainName,
 //                         DomainName);
-    SidEntry->DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
+    SidEntry->DomainName.Length = (USHORT)DomainNameLength * sizeof(WCHAR);
     SidEntry->DomainName.MaximumLength = SidEntry->DomainName.Length + sizeof(WCHAR);
     SidEntry->DomainName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
                                                   SidEntry->DomainName.MaximumLength);
index bb2b36f..5f63144 100644 (file)
@@ -99,7 +99,7 @@ LsarpLookupPrivilegeName(PLUID Value,
             if (NameBuffer == NULL)
                 return STATUS_NO_MEMORY;
 
-            NameBuffer->Length = wcslen(WellKnownPrivileges[Priv].Name) * sizeof(WCHAR);
+            NameBuffer->Length = (USHORT)wcslen(WellKnownPrivileges[Priv].Name) * sizeof(WCHAR);
             NameBuffer->MaximumLength = NameBuffer->Length + sizeof(WCHAR);
 
             NameBuffer->Buffer = MIDL_user_allocate(NameBuffer->MaximumLength);
@@ -354,7 +354,7 @@ LsapLookupAccountRightName(ULONG RightValue,
             if (NameBuffer == NULL)
                 return STATUS_NO_MEMORY;
 
-            NameBuffer->Length = wcslen(WellKnownRights[i].Name) * sizeof(WCHAR);
+            NameBuffer->Length = (USHORT)wcslen(WellKnownRights[i].Name) * sizeof(WCHAR);
             NameBuffer->MaximumLength = NameBuffer->Length + sizeof(WCHAR);
 
             NameBuffer->Buffer = MIDL_user_allocate(NameBuffer->MaximumLength);
index 106a4eb..e4f5abc 100644 (file)
@@ -580,7 +580,7 @@ DoChangePassword(
     Ptr = (LPWSTR)((ULONG_PTR)RequestBuffer + sizeof(MSV1_0_CHANGEPASSWORD_REQUEST));
 
     /* Pack the domain name */
-    RequestBuffer->DomainName.Length = wcslen(Domain) * sizeof(WCHAR);
+    RequestBuffer->DomainName.Length = (USHORT)wcslen(Domain) * sizeof(WCHAR);
     RequestBuffer->DomainName.MaximumLength = RequestBuffer->DomainName.Length + sizeof(WCHAR);
     RequestBuffer->DomainName.Buffer = Ptr;
 
@@ -591,7 +591,7 @@ DoChangePassword(
     Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->DomainName.MaximumLength);
 
     /* Pack the user name */
-    RequestBuffer->AccountName.Length = wcslen(UserName) * sizeof(WCHAR);
+    RequestBuffer->AccountName.Length = (USHORT)wcslen(UserName) * sizeof(WCHAR);
     RequestBuffer->AccountName.MaximumLength = RequestBuffer->AccountName.Length + sizeof(WCHAR);
     RequestBuffer->AccountName.Buffer = Ptr;
 
@@ -602,7 +602,7 @@ DoChangePassword(
     Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->AccountName.MaximumLength);
 
     /* Pack the old password */
-    RequestBuffer->OldPassword.Length = wcslen(OldPassword) * sizeof(WCHAR);
+    RequestBuffer->OldPassword.Length = (USHORT)wcslen(OldPassword) * sizeof(WCHAR);
     RequestBuffer->OldPassword.MaximumLength = RequestBuffer->OldPassword.Length + sizeof(WCHAR);
     RequestBuffer->OldPassword.Buffer = Ptr;
 
@@ -613,7 +613,7 @@ DoChangePassword(
     Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->OldPassword.MaximumLength);
 
     /* Pack the new password */
-    RequestBuffer->NewPassword.Length = wcslen(NewPassword1) * sizeof(WCHAR);
+    RequestBuffer->NewPassword.Length = (USHORT)wcslen(NewPassword1) * sizeof(WCHAR);
     RequestBuffer->NewPassword.MaximumLength = RequestBuffer->NewPassword.Length + sizeof(WCHAR);
     RequestBuffer->NewPassword.Buffer = Ptr;
 
index a6c9fd7..2ab9232 100644 (file)
@@ -102,18 +102,24 @@ BuildInteractiveProfileBuffer(IN PLSA_CLIENT_REQUEST ClientRequest,
     PVOID ClientBaseAddress = NULL;
     LPWSTR Ptr;
     ULONG BufferLength;
+    USHORT ComputerNameLength;
     NTSTATUS Status = STATUS_SUCCESS;
 
     *ProfileBuffer = NULL;
     *ProfileBufferLength = 0;
 
+    if (UIntPtrToUShort(wcslen(ComputerName), &ComputerNameLength) != S_OK)
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
     BufferLength = sizeof(MSV1_0_INTERACTIVE_PROFILE) +
                    UserInfo->All.FullName.Length + sizeof(WCHAR) +
                    UserInfo->All.HomeDirectory.Length + sizeof(WCHAR) +
                    UserInfo->All.HomeDirectoryDrive.Length + sizeof(WCHAR) +
                    UserInfo->All.ScriptPath.Length + sizeof(WCHAR) +
                    UserInfo->All.ProfilePath.Length + sizeof(WCHAR) +
-                   ((wcslen(ComputerName) + 3) * sizeof(WCHAR));
+                   ((ComputerNameLength + 3) * sizeof(WCHAR));
 
     LocalBuffer = DispatchTable.AllocateLsaHeap(BufferLength);
     if (LocalBuffer == NULL)
@@ -204,7 +210,7 @@ BuildInteractiveProfileBuffer(IN PLSA_CLIENT_REQUEST ClientRequest,
 
     Ptr = (LPWSTR)((ULONG_PTR)Ptr + LocalBuffer->HomeDirectoryDrive.MaximumLength);
 
-    LocalBuffer->LogonServer.Length = (wcslen(ComputerName) + 2) * sizeof(WCHAR);
+    LocalBuffer->LogonServer.Length = (ComputerNameLength + 2) * sizeof(WCHAR);
     LocalBuffer->LogonServer.MaximumLength = LocalBuffer->LogonServer.Length + sizeof(WCHAR);
     LocalBuffer->LogonServer.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
     wcscpy(Ptr, L"\\");
index 99aeda9..462fb56 100644 (file)
@@ -8,6 +8,7 @@
 #include <windef.h>
 #include <winbase.h>
 #include <winreg.h>
+#include <intsafe.h>
 #define NTOS_MODE_USER
 #include <ndk/cmfuncs.h>
 #include <ndk/kefuncs.h>
index 7eea9a8..c519fea 100644 (file)
@@ -403,12 +403,19 @@ AccpOpenLSAPolicyHandle(IN LPWSTR SystemName,
 {
     LSA_OBJECT_ATTRIBUTES LsaObjectAttributes = {0};
     LSA_UNICODE_STRING LsaSystemName, *psn;
+    SIZE_T SystemNameLength;
     NTSTATUS Status;
 
     if (SystemName != NULL && SystemName[0] != L'\0')
     {
+        SystemNameLength = wcslen(SystemName);
+        if (SystemNameLength > UNICODE_STRING_MAX_CHARS)
+        {
+            return ERROR_INVALID_PARAMETER;
+        }
+
         LsaSystemName.Buffer = SystemName;
-        LsaSystemName.Length = wcslen(SystemName) * sizeof(WCHAR);
+        LsaSystemName.Length = (USHORT)SystemNameLength * sizeof(WCHAR);
         LsaSystemName.MaximumLength = LsaSystemName.Length + sizeof(WCHAR);
         psn = &LsaSystemName;
     }
@@ -498,10 +505,17 @@ AccpLookupSidByName(IN LSA_HANDLE PolicyHandle,
     PLSA_REFERENCED_DOMAIN_LIST ReferencedDomains = NULL;
     PLSA_TRANSLATED_SID2 TranslatedSid = NULL;
     DWORD SidLen;
+    SIZE_T NameLength;
     DWORD Ret = ERROR_SUCCESS;
 
+    NameLength = wcslen(Name);
+    if (NameLength > UNICODE_STRING_MAX_CHARS)
+    {
+        return ERROR_INVALID_PARAMETER;
+    }
+
     LsaNames[0].Buffer = Name;
-    LsaNames[0].Length = wcslen(Name) * sizeof(WCHAR);
+    LsaNames[0].Length = (USHORT)NameLength * sizeof(WCHAR);
     LsaNames[0].MaximumLength = LsaNames[0].Length + sizeof(WCHAR);
 
     Status = LsaLookupNames2(PolicyHandle,
index cd5d74e..5fc8ab4 100644 (file)
@@ -784,16 +784,24 @@ HRESULT STDMETHODCALLTYPE CShellLink::Load(IStream *stm)
  */
 static HRESULT Stream_WriteString(IStream* stm, LPCWSTR str)
 {
-    USHORT len = wcslen(str) + 1; // FIXME: Possible overflows?
+    SIZE_T length;
+    USHORT len;
     DWORD count;
 
+    length = wcslen(str) + 1;
+    if (length > MAXUSHORT)
+    {
+        return E_INVALIDARG;
+    }
+
+    len = (USHORT)length;
     HRESULT hr = stm->Write(&len, sizeof(len), &count);
     if (FAILED(hr))
         return hr;
 
-    len *= sizeof(WCHAR);
+    length *= sizeof(WCHAR);
 
-    hr = stm->Write(str, len, &count);
+    hr = stm->Write(str, (ULONG)length, &count);
     if (FAILED(hr))
         return hr;
 
index 83290cc..0f437ea 100644 (file)
@@ -102,17 +102,25 @@ static LPITEMIDLIST _ILCreatePrinterItem(PRINTER_INFO_4W *pi)
     PIDLPrinterStruct * p;
     int size0 = (char*)&tmp.u.cprinter.szName - (char*)&tmp.u.cprinter;
     int size = size0;
+    SIZE_T cchPrinterName, cchServerName;
+
+    cchPrinterName = wcslen(pi->pPrinterName);
+    cchServerName = wcslen(pi->pServerName);
+    if ((cchPrinterName + cchServerName) > (MAXUSHORT - 2))
+    {
+        return NULL;
+    }
 
     tmp.type = 0x00;
     tmp.u.cprinter.dummy = 0xFF;
     if (pi->pPrinterName)
-        tmp.u.cprinter.offsServer = wcslen(pi->pPrinterName) + 1;
+        tmp.u.cprinter.offsServer = cchPrinterName + 1;
     else
         tmp.u.cprinter.offsServer = 1;
 
     size += tmp.u.cprinter.offsServer * sizeof(WCHAR);
     if (pi->pServerName)
-        size += (wcslen(pi->pServerName) + 1) * sizeof(WCHAR);
+        size += (cchServerName + 1) * sizeof(WCHAR);
     else
         size += sizeof(WCHAR);
 
index 1a784ed..bae8bf8 100644 (file)
@@ -38,10 +38,20 @@ SetAccountsDomainSid(
     SAM_HANDLE DomainHandle = NULL;
     DOMAIN_NAME_INFORMATION DomainNameInfo;
 
+    SIZE_T DomainNameLength = 0;
     NTSTATUS Status;
 
     DPRINT("SYSSETUP: SetAccountsDomainSid\n");
 
+    if (DomainName != NULL)
+    {
+        DomainNameLength = wcslen(DomainName);
+        if (DomainNameLength > UNICODE_STRING_MAX_CHARS)
+        {
+            return STATUS_INVALID_PARAMETER;
+        }
+    }
+
     memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
     ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
 
@@ -69,7 +79,7 @@ SetAccountsDomainSid(
         else
         {
             Info.DomainName.Buffer = (LPWSTR)DomainName;
-            Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
+            Info.DomainName.Length = DomainNameLength * sizeof(WCHAR);
             Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
         }
 
@@ -81,7 +91,7 @@ SetAccountsDomainSid(
     else
     {
         Info.DomainName.Buffer = (LPWSTR)DomainName;
-        Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
+        Info.DomainName.Length = DomainNameLength * sizeof(WCHAR);
         Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
         Info.DomainSid = DomainSid;
     }
@@ -99,7 +109,7 @@ SetAccountsDomainSid(
 
     LsaClose(PolicyHandle);
 
-    DomainNameInfo.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
+    DomainNameInfo.DomainName.Length = DomainNameLength * sizeof(WCHAR);
     DomainNameInfo.DomainName.MaximumLength = DomainNameInfo.DomainName.Length + sizeof(WCHAR);
     DomainNameInfo.DomainName.Buffer = (LPWSTR)DomainName;
 
@@ -147,10 +157,20 @@ SetPrimaryDomain(LPCWSTR DomainName,
     POLICY_PRIMARY_DOMAIN_INFO Info;
     LSA_OBJECT_ATTRIBUTES ObjectAttributes;
     LSA_HANDLE PolicyHandle;
+    SIZE_T DomainNameLength = 0;
     NTSTATUS Status;
 
     DPRINT1("SYSSETUP: SetPrimaryDomain()\n");
 
+    if (DomainName != NULL)
+    {
+        DomainNameLength = wcslen(DomainName);
+        if (DomainNameLength > UNICODE_STRING_MAX_CHARS)
+        {
+            return STATUS_INVALID_PARAMETER;
+        }
+    }
+
     memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
     ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
 
@@ -178,7 +198,7 @@ SetPrimaryDomain(LPCWSTR DomainName,
         else
         {
             Info.Name.Buffer = (LPWSTR)DomainName;
-            Info.Name.Length = wcslen(DomainName) * sizeof(WCHAR);
+            Info.Name.Length = DomainNameLength * sizeof(WCHAR);
             Info.Name.MaximumLength = Info.Name.Length + sizeof(WCHAR);
         }
 
@@ -190,7 +210,7 @@ SetPrimaryDomain(LPCWSTR DomainName,
     else
     {
         Info.Name.Buffer = (LPWSTR)DomainName;
-        Info.Name.Length = wcslen(DomainName) * sizeof(WCHAR);
+        Info.Name.Length = DomainNameLength * sizeof(WCHAR);
         Info.Name.MaximumLength = Info.Name.Length + sizeof(WCHAR);
         Info.Sid = DomainSid;
     }
@@ -1251,6 +1271,8 @@ SetNewAccountName(
     if (dwLength == 0)
         return;
 
+    ASSERT(dwLength <= UNICODE_STRING_MAX_CHARS);
+
     pszName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength * sizeof(WCHAR));
     if (pszName == NULL)
     {
@@ -1280,7 +1302,7 @@ SetNewAccountName(
         goto done;
     }
 
-    NameInfo.UserName.Length = wcslen(pszName) * sizeof(WCHAR);
+    NameInfo.UserName.Length = (USHORT)wcslen(pszName) * sizeof(WCHAR);
     NameInfo.UserName.MaximumLength = NameInfo.UserName.Length + sizeof(WCHAR);
     NameInfo.UserName.Buffer = pszName;
     NameInfo.FullName.Length = 0;
index ccf6572..d12721f 100644 (file)
@@ -20,6 +20,7 @@ Abstract:
 typedef PVOID PBCB;     //**** Bcb's are now part of the cache module
 
 #ifdef __REACTOS__
+#undef __volatile
 #define __volatile volatile
 #endif
 
index 7aeff77..13b94ba 100644 (file)
@@ -42,7 +42,7 @@ NpReadAlias(
 {
     PNPFS_QUERY_VALUE_CONTEXT QueryContext = Context;
     PWSTR CurrentString;
-    USHORT Length;
+    SIZE_T Length;
     PNPFS_ALIAS CurrentAlias;
     UNICODE_STRING TempString;
     PUNICODE_STRING CurrentTargetName;
index 8ed1b68..86f354c 100644 (file)
@@ -4,7 +4,7 @@
  * FILE:            drivers/kbdclass/kbdclass.c
  * PURPOSE:         Keyboard class driver
  *
- * PROGRAMMERS:     Hervé Poussineau (hpoussin@reactos.org)
+ * PROGRAMMERS:     Hervé Poussineau (hpoussin@reactos.org)
  */
 
 #include "kbdclass.h"
@@ -321,7 +321,7 @@ CreateClassDeviceObject(
        DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
        DeviceNameU.Length = 0;
        DeviceNameU.MaximumLength =
-               wcslen(L"\\Device\\") * sizeof(WCHAR)    /* "\Device\" */
+               (USHORT)wcslen(L"\\Device\\") * sizeof(WCHAR) /* "\Device\" */
                + DriverExtension->DeviceBaseName.Length /* "KeyboardClass" */
                + 4 * sizeof(WCHAR)                      /* Id between 0 and 9999 */
                + sizeof(UNICODE_NULL);                  /* Final NULL char */
index c12ecd5..dc694b4 100644 (file)
@@ -4,7 +4,7 @@
  * FILE:            drivers/mouclass/mouclass.c
  * PURPOSE:         Mouse class driver
  *
- * PROGRAMMERS:     Hervé Poussineau (hpoussin@reactos.org)
+ * PROGRAMMERS:     Hervé Poussineau (hpoussin@reactos.org)
  */
 
 #include "mouclass.h"
@@ -297,7 +297,7 @@ CreateClassDeviceObject(
        DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
        DeviceNameU.Length = 0;
        DeviceNameU.MaximumLength =
-               wcslen(L"\\Device\\") * sizeof(WCHAR)    /* "\Device\" */
+               (USHORT)wcslen(L"\\Device\\") * sizeof(WCHAR)    /* "\Device\" */
                + DriverExtension->DeviceBaseName.Length /* "PointerClass" */
                + 4 * sizeof(WCHAR)                      /* Id between 0 and 9999 */
                + sizeof(UNICODE_NULL);                  /* Final NULL char */
index e6073a9..11875e5 100644 (file)
@@ -266,7 +266,7 @@ DeviceIoctlPassive(PDRIVE_INFO DriveInfo, PIRP Irp)
         }
 
         UniqueId = Irp->AssociatedIrp.SystemBuffer;
-        UniqueId->UniqueIdLength = wcslen(&DriveInfo->DeviceNameBuffer[0]) * sizeof(WCHAR);
+        UniqueId->UniqueIdLength = (USHORT)wcslen(&DriveInfo->DeviceNameBuffer[0]) * sizeof(WCHAR);
 
         if(OutputLength < FIELD_OFFSET(MOUNTDEV_UNIQUE_ID, UniqueId) + UniqueId->UniqueIdLength)
         {
@@ -291,7 +291,7 @@ DeviceIoctlPassive(PDRIVE_INFO DriveInfo, PIRP Irp)
         }
 
         Name = Irp->AssociatedIrp.SystemBuffer;
-        Name->NameLength = wcslen(&DriveInfo->DeviceNameBuffer[0]) * sizeof(WCHAR);
+        Name->NameLength = (USHORT)wcslen(&DriveInfo->DeviceNameBuffer[0]) * sizeof(WCHAR);
 
         if(OutputLength < FIELD_OFFSET(MOUNTDEV_NAME, Name) + Name->NameLength)
         {
index ee6fd12..fa75e06 100644 (file)
@@ -140,7 +140,7 @@ struct UnicodeString : public RtlUnicodeString {
 
        UnicodeString(size_t len, LPWSTR buffer)
        {
-               alloc_len = len;
+               alloc_len = (WORD)len;
                string_ptr = buffer;
        }
 
index 0675021..4ea5a97 100644 (file)
@@ -233,7 +233,7 @@ extern "C" int wmain (int argc, wchar_t **argv)
 
         // Now set back to the beginning
         ScreenInfo.dwCursorPosition.X = 0;
-        ScreenInfo.dwCursorPosition.Y -= Drives.size();
+        ScreenInfo.dwCursorPosition.Y -= (USHORT)Drives.size();
         SetConsoleCursorPosition (Screen, ScreenInfo.dwCursorPosition);
 
         for (size_t d = 0; d < Drives.size (); d++)
index 35f0221..3814587 100644 (file)
@@ -182,10 +182,10 @@ private:
   }
 
   string present_value( DWORD type, const char *data, DWORD len ) {
-    switch( type ) {
-    default:
+    //switch( type ) {
+    //default:
       return bindump( data, len );
-    }
+    //}
   }
 
   void process_valid_request( HKEY open_reg_key, string key_name ) {
index ff85940..41a273f 100644 (file)
@@ -67,7 +67,7 @@ public:
        virtual BOOL Stop();
        virtual LPCServerClientSocket OnGetSocket(LPCServerSocket lpServerSocket);
        virtual LPCServerClientThread OnGetThread(LPCServerClientSocket Socket);
-       virtual void OnAccept(const LPCServerClientThread lpThread);
+       virtual void OnAccept(LPCServerClientThread lpThread);
 private:
        HTTPdState State;
 };
index 8c9cdce..1859d93 100644 (file)
@@ -44,25 +44,25 @@ WriteStringAt(LPWSTR lpString,
               WORD   wColor)
 {
     DWORD cWritten = 0;
-    WORD  wLen;
+    DWORD dwLen;
 
     if (!lpString || *lpString == 0) return;
 
-    wLen = wcslen(lpString);
+    dwLen = (DWORD)wcslen(lpString);
 
     /* Don't bother writing text when erasing */
     if (wColor)
     {
         WriteConsoleOutputCharacterW(ScreenBuffer,
                                      lpString,
-                                     wLen,
+                                     dwLen,
                                      xy,
                                      &cWritten);
     }
 
     FillConsoleOutputAttribute(ScreenBuffer,
                                wColor,
-                               wLen,
+                               dwLen,
                                xy,
                                &cWritten);
 }
@@ -103,7 +103,7 @@ DisplayTitle(VOID)
     LPWSTR szTitle = L"ReactOS Coders Console Parade";
     COORD  xy;
 
-    xy.X = (ScreenBufferInfo.dwSize.X - wcslen(szTitle)) / 2;
+    xy.X = (ScreenBufferInfo.dwSize.X - (USHORT)wcslen(szTitle)) / 2;
     xy.Y = ScreenBufferInfo.dwSize.Y / 2;
 
     WriteStringAt(szTitle, xy,
index be0bb41..d2f2326 100644 (file)
@@ -106,8 +106,8 @@ void DrawScene(HWND hwnd, HDC dc, int ticks)
     angle += ticks * 0.01;
     colorh += ticks * 0.003;
     if (colorh > 360.0) colorh -= 360.0;
-    HLStoRGB(colorh, 1.0, 0.7, &rval, &gval, &bval);
-    DrawCylinder(lvls, angle, 0.2);
+    HLStoRGB(colorh, 1.0f, 0.7f, &rval, &gval, &bval);
+    DrawCylinder(lvls, angle, 0.2f);
     SwapBuffers(dc);
     EndPaint(hwnd, &ps);
 }
@@ -134,7 +134,7 @@ void MyPixelFormat(HDC dc)
 
 void InitGL(HWND hwnd)
 {
-    GLfloat lightpos[4] = {2.0, 2.0, -2.0, 0.7};
+    GLfloat lightpos[4] = {2.0f, 2.0f, -2.0f, 0.7f};
     GLfloat ca = 1.0;
     dc = GetDC(hwnd);
     MyPixelFormat(dc);
index 14b114e..51a9905 100644 (file)
@@ -8,6 +8,7 @@
 #ifdef HAVE_APITEST
     #include <apitest.h>
     #define ATLASSUME(x) /*empty*/
+    #undef ATLASSERT
     #define ATLASSERT(x) /*empty*/
 #else
     #include "atltest.h"
index c5bb6d6..cb10a4d 100644 (file)
@@ -159,7 +159,7 @@ typedef ACPI_ENUM_CHILDREN_OUTPUT_BUFFER UNALIGNED *PACPI_ENUM_CHILDREN_OUTPUT_B
 
 #define ACPI_METHOD_SET_ARGUMENT_STRING( Argument, StrData )                \
   { Argument->Type = ACPI_METHOD_ARGUMENT_STRING;                           \
-    Argument->DataLength = strlen((PCHAR)StrData) + sizeof(UCHAR);          \
+    Argument->DataLength = (USHORT)strlen((PCHAR)StrData) + sizeof(UCHAR);  \
     RtlCopyMemory(&Argument->Data[0],(PUCHAR)StrData,Argument->DataLength); }
 
 #define ACPI_METHOD_SET_ARGUMENT_BUFFER( Argument, BuffData, BuffLength )   \
index 6404ed3..6e78f6b 100644 (file)
@@ -46,9 +46,11 @@ typedef _Return_type_success_(return >= 0) long NTSTATUS;
 #ifndef _HRESULT_DEFINED
 typedef _Return_type_success_(return >= 0) long HRESULT;
 #endif
+#ifndef SUCCEEDED
 #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
 #define FAILED(hr) (((HRESULT)(hr)) < 0)
 #define S_OK    ((HRESULT)0L)
+#endif
 #define INTSAFE_RESULT HRESULT
 #define INTSAFE_SUCCESS S_OK
 #define INTSAFE_E_ARITHMETIC_OVERFLOW ((HRESULT)0x80070216L)
index 15a4bae..5940993 100644 (file)
@@ -6,7 +6,7 @@
  */
 __int64 CDECL _wtoi64_l(const wchar_t *str, _locale_t locale)
 {
-    ULONGLONG RunningTotal = 0;
+    LONGLONG RunningTotal = 0;
     BOOL bMinus = FALSE;
 
     while (iswctype((int)*str, _SPACE)) {
@@ -191,7 +191,7 @@ unsigned __int64 CDECL _wcstoui64_l(const wchar_t *nptr,
     if(endptr)
         *endptr = (wchar_t*)nptr;
 
-    return negative ? -ret : ret;
+    return negative ? -(__int64)ret : ret;
 }
 
 /*********************************************************************
index c859ac7..815abeb 100644 (file)
@@ -124,7 +124,7 @@ NDIS_STATUS LoopRegisterAdapter(
 
   Loopback->Name.Buffer = L"Loopback";
   Loopback->Name.MaximumLength = Loopback->Name.Length =
-      wcslen(Loopback->Name.Buffer) * sizeof(WCHAR);
+      (USHORT)wcslen(Loopback->Name.Buffer) * sizeof(WCHAR);
 
   AddrInitIPv4(&Loopback->Unicast, LOOPBACK_ADDRESS_IPv4);
   AddrInitIPv4(&Loopback->Netmask, LOOPBACK_ADDRMASK_IPv4);
index d1edc10..dcb7817 100644 (file)
@@ -1131,7 +1131,7 @@ static VOID WINAPI DosInitialize(LPWORD Stack)
     /* Get the DOS BIOS file name (NULL-terminated) */
     // FIXME: Isn't it possible to use some DS:SI instead??
     LPCSTR DosBiosFileName = (LPCSTR)SEG_OFF_TO_PTR(getCS(), getIP());
-    setIP(getIP() + strlen(DosBiosFileName) + 1); // Skip it
+    setIP(getIP() + (USHORT)strlen(DosBiosFileName) + 1); // Skip it
 
     DPRINT("DosInitialize('%s')\n", DosBiosFileName);
 
index 764877d..e592072 100644 (file)
@@ -109,7 +109,7 @@ LONG copy_servername_from_name(LPCWSTR name, LPWSTR target)
 
     FIXME("found %s\n", debugstr_wn(server, serverlen));
 
-    if (serverlen > MAX_COMPUTERNAME_LENGTH) return -serverlen;
+    if (serverlen > MAX_COMPUTERNAME_LENGTH) return -(LONG)serverlen;
 
     if (target)
     {
index 0acf11b..3602c2c 100644 (file)
@@ -111,7 +111,7 @@ ClassNameToVersion(
             ERR("Couldn't get atom name for atom %x !\n", LOWORD((DWORD_PTR)lpszClass));
             return NULL;
         }
-        SectionName.Length = wcslen(SectionNameBuf) * sizeof(WCHAR);
+        SectionName.Length = (USHORT)wcslen(SectionNameBuf) * sizeof(WCHAR);
         TRACE("ClassNameToVersion got name %wZ from atom\n", &SectionName);
     }
     else