From 98fb7a32db1d7eb2f60026b7608b31d742e8df83 Mon Sep 17 00:00:00 2001 From: Notselwyn <68616630+Notselwyn@users.noreply.github.com> Date: Thu, 28 Dec 2023 16:11:26 +0100 Subject: [PATCH 1/3] fix: return val is not true when registry val does not exist --- .../Operations/SessionIntegrityOperation.cs | 5 +++-- SafeExamBrowser.SystemComponents/Registry/Registry.cs | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs b/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs index 87293a64..1649df91 100644 --- a/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs +++ b/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs @@ -113,7 +113,7 @@ namespace SafeExamBrowser.Runtime.Operations if (registry.TryRead(RegistryValue.MachineHive.EaseOfAccess_Key, RegistryValue.MachineHive.EaseOfAccess_Name, out var value)) { - if (value == default || (value is string s && string.IsNullOrWhiteSpace(s))) + if (value is string s && string.IsNullOrWhiteSpace(s)) { success = true; logger.Info("Ease of access configuration successfully verified."); @@ -135,7 +135,8 @@ namespace SafeExamBrowser.Runtime.Operations } else { - logger.Error("Failed to verify ease of access configuration!"); + success = true; + logger.Info("Ease of access configuration successfully verified (value does not exist)."); } return success; diff --git a/SafeExamBrowser.SystemComponents/Registry/Registry.cs b/SafeExamBrowser.SystemComponents/Registry/Registry.cs index 057e6b3c..c97cd2bc 100644 --- a/SafeExamBrowser.SystemComponents/Registry/Registry.cs +++ b/SafeExamBrowser.SystemComponents/Registry/Registry.cs @@ -73,21 +73,20 @@ namespace SafeExamBrowser.SystemComponents.Registry public bool TryRead(string key, string name, out object value) { - var success = false; - + var defaultValue = new object(); + value = default; try { - value = Microsoft.Win32.Registry.GetValue(key, name, default); - success = true; + value = Microsoft.Win32.Registry.GetValue(key, name, defaultValue); } catch (Exception e) { logger.Error($"Failed to read value '{name}' from registry key '{key}'!", e); } - return success; + return value != default && value != defaultValue; } public bool TryGetNames(string keyName, out IEnumerable names) From ebca114c2e69e36048be919bffe3c9d2a09ba323 Mon Sep 17 00:00:00 2001 From: Notselwyn <68616630+Notselwyn@users.noreply.github.com> Date: Thu, 28 Dec 2023 16:15:46 +0100 Subject: [PATCH 2/3] fix: optimized (now redundant) code --- SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs b/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs index 1649df91..4d0696a3 100644 --- a/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs +++ b/SafeExamBrowser.Runtime/Operations/SessionIntegrityOperation.cs @@ -77,7 +77,7 @@ namespace SafeExamBrowser.Runtime.Operations foreach (var cursor in cursors.Where(c => !string.IsNullOrWhiteSpace(c))) { success &= registry.TryRead(RegistryValue.UserHive.Cursors_Key, cursor, out var value); - success &= value == default || !(value is string) || (value is string path && (string.IsNullOrWhiteSpace(path) || IsValidCursorPath(path))); + success &= !(value is string) || (value is string path && (string.IsNullOrWhiteSpace(path) || IsValidCursorPath(path))); if (!success) { From 04571f51b2401f47735894d8c869b002c28e204c Mon Sep 17 00:00:00 2001 From: Notselwyn <68616630+Notselwyn@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:35:32 +0100 Subject: [PATCH 3/3] fix: fixed obj != obj checking (according to devops warnings) --- SafeExamBrowser.SystemComponents/Registry/Registry.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SafeExamBrowser.SystemComponents/Registry/Registry.cs b/SafeExamBrowser.SystemComponents/Registry/Registry.cs index c97cd2bc..e0e1eec5 100644 --- a/SafeExamBrowser.SystemComponents/Registry/Registry.cs +++ b/SafeExamBrowser.SystemComponents/Registry/Registry.cs @@ -86,7 +86,7 @@ namespace SafeExamBrowser.SystemComponents.Registry logger.Error($"Failed to read value '{name}' from registry key '{key}'!", e); } - return value != default && value != defaultValue; + return value != default && !ReferenceEquals(value, defaultValue); } public bool TryGetNames(string keyName, out IEnumerable names)