Author: tfaber Date: Tue Nov 26 15:09:21 2013 New Revision: 61101
URL: http://svn.reactos.org/svn/reactos?rev=61101&view=rev Log: [KERNEL32] - Fix wrong check for realtime priority class in CreateProcessInternalW - Fix double free in GetEnvironmentVariable[AW] - Fix broken sizeof usage ('X' is of type int!) - Remove redundant casts and comparisons
Modified: trunk/reactos/dll/win32/kernel32/client/environ.c trunk/reactos/dll/win32/kernel32/client/proc.c
Modified: trunk/reactos/dll/win32/kernel32/client/environ.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/e... ============================================================================== --- trunk/reactos/dll/win32/kernel32/client/environ.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/environ.c [iso-8859-1] Tue Nov 26 15:09:21 2013 @@ -83,10 +83,10 @@ if ((NT_SUCCESS(Status)) && !(nSize)) Status = STATUS_BUFFER_TOO_SMALL;
/* Check if we didn't have enough space */ - if (!(NT_SUCCESS(Status)) && (Status == STATUS_BUFFER_TOO_SMALL)) + if (Status == STATUS_BUFFER_TOO_SMALL) { /* Fixup the length that the API returned */ - VarValueU.MaximumLength = VarValueU.Length + 2; + VarValueU.MaximumLength = VarValueU.Length + sizeof(UNICODE_NULL);
/* Free old Unicode buffer */ RtlFreeHeap(RtlGetProcessHeap(), 0, VarValueU.Buffer); @@ -108,6 +108,7 @@ { /* Set failure status */ Status = STATUS_NO_MEMORY; + VarValueU.Buffer = NULL; } } else if (NT_SUCCESS(Status)) @@ -373,7 +374,7 @@ WINAPI FreeEnvironmentStringsA(IN LPSTR EnvironmentStrings) { - return (BOOL)RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings); + return RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings); }
/* @@ -383,7 +384,7 @@ WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings) { - return (BOOL)RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings); + return RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings); }
/* @@ -443,7 +444,7 @@ Status = RtlExpandEnvironmentStrings_U(NULL, &SourceU, &DestU, &Length);
/* Check if we didn't have enough space */ - if (!(NT_SUCCESS(Status)) && (Status == STATUS_BUFFER_TOO_SMALL)) + if (Status == STATUS_BUFFER_TOO_SMALL) { /* Fixup the length that the API returned */ DestU.MaximumLength = (SHORT)Length; @@ -468,6 +469,7 @@ { /* Set failure status */ Status = STATUS_NO_MEMORY; + DestU.Buffer = NULL; } } else if (NT_SUCCESS(Status)) @@ -518,8 +520,7 @@ NTSTATUS Status; USHORT UniSize;
- UniSize = UNICODE_STRING_MAX_CHARS - 2; - if (nSize <= UniSize) UniSize = (USHORT)nSize; + UniSize = min(nSize, UNICODE_STRING_MAX_CHARS - 2);
RtlInitUnicodeString(&Source, (LPWSTR)lpSrc); RtlInitEmptyUnicodeString(&Destination, lpDst, UniSize * sizeof(WCHAR));
Modified: trunk/reactos/dll/win32/kernel32/client/proc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/p... ============================================================================== --- trunk/reactos/dll/win32/kernel32/client/proc.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/proc.c [iso-8859-1] Tue Nov 26 15:09:21 2013 @@ -3762,7 +3762,7 @@ }
/* Account for the quotes and space between the two */ - n += ((sizeof('""') * 2) + sizeof(' ')); + n += sizeof("" "") - sizeof(ANSI_NULL);
/* Convert to bytes, and make sure we don't overflow */ n *= sizeof(WCHAR); @@ -3923,7 +3923,7 @@ RealTimePrivilegeState = NULL;
/* Is realtime priority being requested? */ - if (PriorityClass.PriorityClass == REALTIME_PRIORITY_CLASS) + if (PriorityClass.PriorityClass == PROCESS_PRIORITY_CLASS_REALTIME) { /* Check if the caller has real-time access, and enable it if so */ RealTimePrivilegeState = BasepIsRealtimeAllowed(TRUE);