Skip to content

Commit 59b5951

Browse files
authored
Merge pull request #1433 from kpawnd/master
Fix NullReferenceException in RegistryConfiguration when deleting missing registry keys
2 parents 066e84c + 9d6e16c commit 59b5951

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

SafeExamBrowser.Communication.UnitTests/Hosts/BaseHostTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ public class BaseHostTests
2929
[TestInitialize]
3030
public void Initialize()
3131
{
32+
const int HOST_START_TIMEOUT_MS = 1000;
33+
3234
hostObject = new Mock<IHostObject>();
3335
hostObjectFactory = new Mock<IHostObjectFactory>();
3436
logger = new Mock<ILogger>();
3537

3638
hostObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>(), It.IsAny<ICommunication>())).Returns(hostObject.Object);
3739

38-
sut = new BaseHostStub("net.pipe://some/address/here", hostObjectFactory.Object, logger.Object, 10);
40+
sut = new BaseHostStub("net.pipe://some/address/here", hostObjectFactory.Object, logger.Object, HOST_START_TIMEOUT_MS);
3941
}
4042

4143
[TestMethod]

SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/RegistryConfiguration.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,22 @@ private bool TryDelete(RegistryDataItem item)
191191

192192
using (var key = RootKey.OpenSubKey(keyWithoutRoot, true))
193193
{
194-
if (key.GetValue(item.Value) != null)
194+
if (key == null)
195+
{
196+
logger.Debug($"No need to delete registry item {item} as its key does not exist.");
197+
success = true;
198+
}
199+
else if (key.GetValue(item.Value) != null)
195200
{
196201
key.DeleteValue(item.Value);
197202
logger.Debug($"Successfully deleted registry item {item}.");
203+
success = true;
198204
}
199205
else
200206
{
201207
logger.Debug($"No need to delete registry item {item} as it does not exist.");
208+
success = true;
202209
}
203-
204-
success = true;
205210
}
206211
}
207212
else

0 commit comments

Comments
 (0)