From 3200785a27ea313be5bc219a29158be79e649fe7 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 14 Feb 2024 20:03:47 +0100 Subject: [PATCH] Fix NPE in Windows Defender autofix Powershell script on first exclusion If a user has no process-exclusion defined in its Windows Defender configuration yet, the expression '(Get-MpPreference).ExclusionProcess' returns null in the Powershell script to perform the exclusion. If a null reference is read, the variable is now initialized with an empty set. --- .../org/eclipse/ui/internal/WindowsDefenderConfigurator.java | 1 + .../Eclipse UI/org/eclipse/ui/internal/messages.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java index 0a13bdd99f8..b4f79fa1f41 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java @@ -281,6 +281,7 @@ public static String createAddExclusionsPowershellCommand(String extraSeparator) final String exclusionType = "ExclusionProcess"; //$NON-NLS-1$ return String.join(';' + extraSeparator, "$exclusions=@(" + extraSeparator + excludedPaths + ')', //$NON-NLS-1$ "$existingExclusions=[Collections.Generic.HashSet[String]](Get-MpPreference)." + exclusionType, //$NON-NLS-1$ + "if($existingExclusions -eq $null) { $existingExclusions = New-Object Collections.Generic.HashSet[String] }", //$NON-NLS-1$ "$exclusionsToAdd=[Linq.Enumerable]::ToArray([Linq.Enumerable]::Where($exclusions,[Func[object,bool]]{param($ex)!$existingExclusions.Contains($ex)}))", //$NON-NLS-1$ "if($exclusionsToAdd.Length -gt 0){ Add-MpPreference -" + exclusionType + " $exclusionsToAdd }"); //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties index 409502db45e..e9bb1c2efad 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties @@ -579,7 +579,7 @@ WindowsDefenderConfigurator_scriptHideLabel=<< Hide Powershell script WindowsDefenderConfigurator_scriptHint=Adding exclusions respectively running the Powershell script to do this requires administrator privileges. WindowsDefenderConfigurator_performExclusionChoice=Exclude {0} from being scanned to improve performance.\n\ (In general adding exclusions may affect the security level of this computer) -WindowsDefenderConfigurator_ignoreThisInstallationChoice=Keep {0} being scanned by Windows Defender +WindowsDefenderConfigurator_ignoreThisInstallationChoice=Keep {0} being scanned by Windows Defender. WindowsDefenderConfigurator_ignoreAllChoice=Skip exclusion check on startup for all new Eclipse-based installations WindowsDefenderConfigurator_detailsAndOptionsLinkText=See 'Startup and Shutdown' preference for more details and configuration options. WindowsDefenderConfigurator_runExclusionFromPreferenceButtonLabel=Run exclusion check now