diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs index d7a63c81..ad6d9ae9 100644 --- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs +++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs @@ -50,6 +50,15 @@ public DesktopSmartCardDeviceListener() uint result = SCardEstablishContext(SCARD_SCOPE.USER, out SCardContext context); _log.SCardApiCall(nameof(SCardEstablishContext), result); + // If we failed to establish context to the smart card subsystem, something substantially wrong + // has occured. We should not continue, and the device listener should remain dormant. + if (result != ErrorCode.SCARD_S_SUCCESS) + { + _context = new SCardContext(IntPtr.Zero); + _readerStates = Array.Empty(); + return; + } + _context = context; _readerStates = GetReaderStateList();