diff --git a/reactos/lib/kernel32/process/cmdline.c b/reactos/lib/kernel32/process/cmdline.c index 9412f6a9ead..b3b6d61d2ce 100644 --- a/reactos/lib/kernel32/process/cmdline.c +++ b/reactos/lib/kernel32/process/cmdline.c @@ -1,4 +1,5 @@ -/* +/* $Id: cmdline.c,v 1.9 1999/12/10 17:47:29 ekohl Exp $ + * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/kernel32/proc/proc.c @@ -10,7 +11,7 @@ /* INCLUDES ****************************************************************/ -#define UNICODE +//#define UNICODE #include #include #include @@ -18,29 +19,76 @@ #include #include #include +#include + +#define NDEBUG +#include /* GLOBALS ******************************************************************/ +static UNICODE_STRING CommandLineStringW; +static ANSI_STRING CommandLineStringA; + +static WCHAR CommandLineW[MAX_PATH]; static CHAR CommandLineA[MAX_PATH]; +static WINBOOL bCommandLineInitialized = FALSE; + + /* FUNCTIONS ****************************************************************/ +static VOID +InitCommandLines (VOID) +{ + PPPB Ppb; + + // initialize command line buffers + CommandLineW[0] = 0; + CommandLineStringW.Buffer = CommandLineW; + CommandLineStringW.Length = 0; + CommandLineStringW.MaximumLength = MAX_PATH * sizeof(WCHAR); + + CommandLineA[0] = 0; + CommandLineStringA.Buffer = CommandLineA; + CommandLineStringA.Length = 0; + CommandLineStringA.MaximumLength = MAX_PATH; + + // get command line + Ppb = NtCurrentPeb()->Ppb; + RtlNormalizeProcessParams (Ppb); + + RtlCopyUnicodeString (&CommandLineStringW, + &(Ppb->CommandLine)); + RtlUnicodeStringToAnsiString (&CommandLineStringA, + &CommandLineStringW, + FALSE); + + bCommandLineInitialized = TRUE; +} + + LPSTR STDCALL GetCommandLineA(VOID) { - ULONG i; - PWSTR CommandLineW; - - CommandLineW = GetCommandLineW(); - for (i=0; iPpb->CommandLine.Buffer); + if (bCommandLineInitialized == FALSE) + { + InitCommandLines (); + } + + DPRINT ("CommandLine \'%w\'\n", CommandLineW); + + return(CommandLineW); } +/* EOF */ \ No newline at end of file diff --git a/reactos/lib/kernel32/process/create.c b/reactos/lib/kernel32/process/create.c index a03709c19e8..e61216026c2 100644 --- a/reactos/lib/kernel32/process/create.c +++ b/reactos/lib/kernel32/process/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.15 1999/12/08 12:58:44 ekohl Exp $ +/* $Id: create.c,v 1.16 1999/12/10 17:47:29 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -359,23 +359,7 @@ CreatePeb ( ULONG PpbSize; ULONG BytesWritten; - PebBase = (PVOID)PEB_BASE; - PebSize = 0x1000; - - NtReadVirtualMemory(ProcessHandle, - (PVOID)PEB_BASE, - &Peb, - sizeof(Peb), - &BytesWritten); - - Peb.Ppb = (PPPB)PEB_STARTUPINFO; - - NtWriteVirtualMemory(ProcessHandle, - (PVOID)PEB_BASE, - &Peb, - sizeof(Peb), - &BytesWritten); - + /* create the PPB */ PpbBase = (PVOID)PEB_STARTUPINFO; PpbSize = Ppb->TotalSize; Status = NtAllocateVirtualMemory(ProcessHandle, @@ -389,13 +373,39 @@ CreatePeb ( return(Status); } - DPRINT("Ppb size %x\n", Ppb->TotalSize); - ZwWriteVirtualMemory(ProcessHandle, - (PVOID)PEB_STARTUPINFO, - &Ppb, + DPRINT("Ppb->TotalSize %x\n", Ppb->TotalSize); + NtWriteVirtualMemory(ProcessHandle, + PpbBase, + Ppb, Ppb->TotalSize, &BytesWritten); + + /* create the PEB */ + PebBase = (PVOID)PEB_BASE; + PebSize = 0x1000; + + Status = NtAllocateVirtualMemory(ProcessHandle, + &PebBase, + 0, + &PebSize, + MEM_COMMIT, + PAGE_READWRITE); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + DPRINT("Peb created\n"); + + Peb.Ppb = (PPPB)PpbBase; + + NtWriteVirtualMemory(ProcessHandle, + PebBase, + &Peb, + sizeof(Peb), + &BytesWritten); + *PebPtr = (PPEB)PebBase; return(STATUS_SUCCESS); @@ -459,6 +469,8 @@ CreateProcessW ( &CommandLine_U, TempCommandLine); + DPRINT("CommandLine_U %w\n", CommandLine_U.Buffer); + RtlCreateProcessParameters ( &Ppb, &CommandLine_U, diff --git a/reactos/lib/ntdll/rtl/process.c b/reactos/lib/ntdll/rtl/process.c index ea84b41d7de..967dcc14344 100644 --- a/reactos/lib/ntdll/rtl/process.c +++ b/reactos/lib/ntdll/rtl/process.c @@ -1,4 +1,4 @@ -/* $Id: process.c,v 1.6 1999/12/08 12:58:26 ekohl Exp $ +/* $Id: process.c,v 1.7 1999/12/10 17:48:34 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -477,7 +477,7 @@ RtlCreateProcessParameters ( DataSize += (Reserved->Length + sizeof(WCHAR)); /* Calculate the required block size */ - RegionSize = DataSize; + RegionSize = ROUNDUP(DataSize, PAGESIZE); Status = NtAllocateVirtualMemory ( NtCurrentProcess (), diff --git a/reactos/lib/ntdll/rtl/unicode.c b/reactos/lib/ntdll/rtl/unicode.c index 7320e7ae53c..04fe8ba91b8 100644 --- a/reactos/lib/ntdll/rtl/unicode.c +++ b/reactos/lib/ntdll/rtl/unicode.c @@ -1,4 +1,4 @@ -/* $Id: unicode.c,v 1.10 1999/11/25 23:43:44 ekohl Exp $ +/* $Id: unicode.c,v 1.11 1999/12/10 17:48:34 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -81,8 +81,6 @@ RtlAnsiStringToUnicodeString( if (Length > 65535) return STATUS_INVALID_PARAMETER_2; - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(WCHAR); @@ -95,9 +93,10 @@ RtlAnsiStringToUnicodeString( } else { - if (Length > DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -470,7 +469,6 @@ RtlDowncaseUnicodeString ( if (AllocateDestinationString == TRUE) { - DestinationString->Length = SourceString->Length; DestinationString->MaximumLength = SourceString->Length + sizeof(WCHAR); DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (), 0, @@ -479,8 +477,9 @@ RtlDowncaseUnicodeString ( else { if (SourceString->Length >= DestinationString->MaximumLength) - return STATUS_BUFFER_OVERFLOW; + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = SourceString->Length; Src = SourceString->Buffer; Dest = DestinationString->Buffer; @@ -855,8 +854,6 @@ RtlOemStringToUnicodeString ( if (Length > 65535) return STATUS_INVALID_PARAMETER_2; - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(WCHAR); @@ -869,13 +866,13 @@ RtlOemStringToUnicodeString ( } else { - if (Length > DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length > DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; - memset (DestinationString->Buffer, - 0, - DestinationString->Length); + RtlZeroMemory (DestinationString->Buffer, + DestinationString->Length); Status = RtlOemToUnicodeN (DestinationString->Buffer, DestinationString->Length, @@ -931,12 +928,6 @@ RtlUnicodeStringToAnsiString ( else Length = SourceString->Length / sizeof(WCHAR); - /* this doesn't make sense */ -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -949,9 +940,10 @@ RtlUnicodeStringToAnsiString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -963,10 +955,12 @@ RtlUnicodeStringToAnsiString ( SourceString->Length); if (!NT_SUCCESS(Status)) { - if (AllocateDestinationString) + if (AllocateDestinationString == TRUE) + { RtlFreeHeap (RtlGetProcessHeap (), 0, DestinationString->Buffer); + } return Status; } @@ -1079,11 +1073,6 @@ RtlUnicodeStringToOemString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -1096,9 +1085,10 @@ RtlUnicodeStringToOemString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -1154,8 +1144,6 @@ RtlUpcaseUnicodeString ( ULONG i; PWCHAR Src, Dest; - DestinationString->Length = SourceString->Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength=SourceString->Length+sizeof(WCHAR); @@ -1165,6 +1153,12 @@ RtlUpcaseUnicodeString ( if (DestinationString->Buffer == NULL) return STATUS_NO_MEMORY; } + else + { + if (SourceString->Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; + } + DestinationString->Length = SourceString->Length; Src = SourceString->Buffer; Dest = DestinationString->Buffer; @@ -1196,11 +1190,6 @@ RtlUpcaseUnicodeStringToAnsiString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -1212,9 +1201,10 @@ RtlUpcaseUnicodeStringToAnsiString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -1262,11 +1252,6 @@ RtlUpcaseUnicodeStringToOemString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -1278,9 +1263,10 @@ RtlUpcaseUnicodeStringToOemString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); diff --git a/reactos/ntoskrnl/rtl/unicode.c b/reactos/ntoskrnl/rtl/unicode.c index 6e7a3e33324..7a71e1f9d57 100644 --- a/reactos/ntoskrnl/rtl/unicode.c +++ b/reactos/ntoskrnl/rtl/unicode.c @@ -1,4 +1,4 @@ -/* $Id: unicode.c,v 1.10 1999/11/25 23:34:43 ekohl Exp $ +/* $Id: unicode.c,v 1.11 1999/12/10 17:49:21 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -76,8 +76,6 @@ RtlAnsiStringToUnicodeString ( if (Length > 65535) return STATUS_INVALID_PARAMETER_2; - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(WCHAR); @@ -89,13 +87,13 @@ RtlAnsiStringToUnicodeString ( } else { - if (Length > DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length > DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; - memset (DestinationString->Buffer, - 0, - DestinationString->Length); + RtlZeroMemory (DestinationString->Buffer, + DestinationString->Length); Status = RtlMultiByteToUnicodeN (DestinationString->Buffer, DestinationString->Length, @@ -464,7 +462,6 @@ RtlDowncaseUnicodeString ( if (AllocateDestinationString == TRUE) { - DestinationString->Length = SourceString->Length; DestinationString->MaximumLength = SourceString->Length + sizeof(WCHAR); DestinationString->Buffer = ExAllocatePool (NonPagedPool, SourceString->Length + sizeof(WCHAR)); @@ -474,8 +471,9 @@ RtlDowncaseUnicodeString ( else { if (SourceString->Length >= DestinationString->MaximumLength) - return STATUS_BUFFER_OVERFLOW; + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = SourceString->Length; Src = SourceString->Buffer; Dest = DestinationString->Buffer; @@ -844,8 +842,6 @@ RtlOemStringToUnicodeString ( if (Length > 65535) return STATUS_INVALID_PARAMETER_2; - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(WCHAR); @@ -857,13 +853,13 @@ RtlOemStringToUnicodeString ( } else { - if (Length > DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; - memset (DestinationString->Buffer, - 0, - DestinationString->Length); + RtlZeroMemory (DestinationString->Buffer, + DestinationString->Length); Status = RtlOemToUnicodeN (DestinationString->Buffer, DestinationString->Length, @@ -913,11 +909,6 @@ RtlUnicodeStringToAnsiString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -928,9 +919,10 @@ RtlUnicodeStringToAnsiString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -1058,11 +1050,6 @@ RtlUnicodeStringToOemString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -1074,9 +1061,10 @@ RtlUnicodeStringToOemString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -1130,7 +1118,6 @@ RtlUpcaseUnicodeString ( if (AllocateDestinationString == TRUE) { - DestinationString->Length = SourceString->Length; DestinationString->MaximumLength = SourceString->Length + sizeof(WCHAR); DestinationString->Buffer = ExAllocatePool (NonPagedPool, SourceString->Length + sizeof(WCHAR)); @@ -1140,8 +1127,9 @@ RtlUpcaseUnicodeString ( else { if (SourceString->Length >= DestinationString->MaximumLength) - return STATUS_BUFFER_OVERFLOW; + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = SourceString->Length; Src = SourceString->Buffer; Dest = DestinationString->Buffer; @@ -1173,11 +1161,6 @@ RtlUpcaseUnicodeStringToAnsiString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -1188,9 +1171,10 @@ RtlUpcaseUnicodeStringToAnsiString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length); @@ -1234,11 +1218,6 @@ RtlUpcaseUnicodeStringToOemString ( else Length = SourceString->Length / sizeof(WCHAR); -// if (Length > 65535) -// return STATUS_INVALID_PARAMETER_2; - - DestinationString->Length = Length; - if (AllocateDestinationString == TRUE) { DestinationString->MaximumLength = Length + sizeof(CHAR); @@ -1249,9 +1228,10 @@ RtlUpcaseUnicodeStringToOemString ( } else { - if (Length >= DestinationString->Length) - return STATUS_BUFFER_OVERFLOW; + if (Length >= DestinationString->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; } + DestinationString->Length = Length; RtlZeroMemory (DestinationString->Buffer, DestinationString->Length);