From 3238535a4d199207daf34ed15090b9ea6c639d5a Mon Sep 17 00:00:00 2001 From: George Chakhidze <0xfeeddeadbeef@gmail.com> Date: Wed, 12 Apr 2017 23:03:35 +0400 Subject: [PATCH] Use IntPtr(-1) for INVALID_HANDLE_VALUE instead of IntPtr.Zero - Fix incorrect handling of GetCurrentProcess() API return value in IsWow64() function (MainEntry.cpp) - Remove unused INVALID_HANDLE_VALUE field from ProcessNativeMethods class (Process.cs) Fixes #3540 --- .../commands/management/Process.cs | 1 - src/System.Management.Automation/utils/PlatformInvokes.cs | 2 +- src/powershell-native/nativemsh/pwrshexe/MainEntry.cpp | 7 +------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index d0264581fc5..206f5a6b9e6 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -2608,7 +2608,6 @@ internal struct JOBOBJECT_BASIC_PROCESS_ID_LIST internal static class ProcessNativeMethods { // Fields - internal static readonly IntPtr INVALID_HANDLE_VALUE = IntPtr.Zero; internal static UInt32 GENERIC_READ = 0x80000000; internal static UInt32 GENERIC_WRITE = 0x40000000; internal static UInt32 FILE_ATTRIBUTE_NORMAL = 0x80000000; diff --git a/src/System.Management.Automation/utils/PlatformInvokes.cs b/src/System.Management.Automation/utils/PlatformInvokes.cs index aec86dee95d..1706d242a4e 100644 --- a/src/System.Management.Automation/utils/PlatformInvokes.cs +++ b/src/System.Management.Automation/utils/PlatformInvokes.cs @@ -558,7 +558,7 @@ internal struct PRIVILEGE_SET #if !UNIX // Fields - internal static readonly IntPtr INVALID_HANDLE_VALUE = IntPtr.Zero; + internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); internal static UInt32 GENERIC_READ = 0x80000000; internal static UInt32 GENERIC_WRITE = 0x40000000; internal static UInt32 FILE_ATTRIBUTE_NORMAL = 0x80000000; diff --git a/src/powershell-native/nativemsh/pwrshexe/MainEntry.cpp b/src/powershell-native/nativemsh/pwrshexe/MainEntry.cpp index e7a2777d183..5b51e99e151 100644 --- a/src/powershell-native/nativemsh/pwrshexe/MainEntry.cpp +++ b/src/powershell-native/nativemsh/pwrshexe/MainEntry.cpp @@ -1139,11 +1139,6 @@ BOOL IsWow64() { HANDLE hCurrentProc = GetCurrentProcess(); - if (INVALID_HANDLE_VALUE == hCurrentProc) - { - return false; - } - BOOL isWow64Process = FALSE; BOOL ret = IsWow64Process(hCurrentProc, &isWow64Process); @@ -1152,7 +1147,7 @@ BOOL IsWow64() return isWow64Process; } - return false; + return FALSE; } /**********************************************************************