Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

OpenSCManager may fail on Windows 2008 R2 when called from an atexit() function


Symptoms

When called from an atexit() function OpenSCManager may fail on Windows 2008 R2 with the following exception stack trace:


(608.129c): Access violation - code c0000005 (!!! second chance !!!)
SspiCli!CallSPM+0x26:
000007fe`fced16a2 488b4918        mov     rcx,qword ptr [rcx+18h] ds:00000000`022fbfe8=????????????????

Child-SP          RetAddr           Call Site
00000000`001217e0 000007fe`fced4fb5 SspiCli!CallSPM+0x26
00000000`00121810 000007fe`fced4c2f SspiCli!SecpGetBinding+0xa3
00000000`00121a40 000007fe`fced4a92 SspiCli!SecpLoadLsaPackages+0xb3
00000000`00121b50 000007fe`fced1604 SspiCli!SecpLocatePackageEx+0x127
00000000`00121ba0 000007fe`fced426d SspiCli!SecLocatePackageById+0x34
00000000`00121bf0 000007fe`ff294f9e SspiCli!EnumerateSecurityPackagesW+0x21
00000000`00121c20 000007fe`ff278ed1 RPCRT4!FindSecurityPackage+0x20c
00000000`00121c90 000007fe`ff29347f RPCRT4!SECURITY_CREDENTIALS::AcquireCredentialsForClient+0x51
00000000`00121d50 000007fe`ff29d647 RPCRT4!BINDING_HANDLE::SetAuthInformation+0x19f
00000000`00121dd0 000007fe`fee6b8a9 RPCRT4!RpcBindingSetAuthInfoExW+0x1a7
00000000`00121ec0 000007fe`fee6b3b7 sechost!ScClientBindToServerUsingTCP+0x365
00000000`00121f90 000007fe`fee6b0a2 sechost!ScClientBindToServer+0x287
00000000`001220a0 000007fe`ff2bad10 sechost!SVCCTL_HANDLEW_bind+0xe
00000000`001220d0 000007fe`ff34fe74 RPCRT4!GenericHandleMgr+0x88
00000000`00122100 000007fe`ff350c0d RPCRT4!NdrpClientCall2+0xa79
00000000`00122870 000007fe`fee66609 RPCRT4!NdrClientCall2+0x1d
00000000`001228a0 00000000`03e4b78b sechost!OpenSCManagerW+0x6d

↑ Back to the top


Cause

The exception happens because of a bug in the SSPI module.  SSPI frees an internal RPC handle when the process is shutting down.  When OpenSCManager is called within an atexit() function, SSPI attempts to use the freed RPC handle causing an exception.

↑ Back to the top


Resolution

There is currently no workaround other than to not call OpenSCManager within an atexit() function.

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2556091
Revision : 1
Created on : 1/7/2017
Published on : 5/24/2011
Exists online : False
Views : 708