Potential Depth Overflow Bug in Microsoft.SME.AzureCenter\Resolve-DnsName

%3CLINGO-SUB%20id%3D%22lingo-sub-1608301%22%20slang%3D%22en-US%22%3EPotential%20Depth%20Overflow%20Bug%20in%20Microsoft.SME.AzureCenter%5CResolve-DnsName%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1608301%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20encountered%20a%20strange%20issue%20that%20was%20manifesting%20itself%20as%20a%20depth%20overflow%20bug%20while%20Invoking%20Test-NetConnection%20on%20a%20collection%20of%20servers.%20I%20have%20identified%20that%20this%20issue%20I%20am%20seeing%20is%20ultimately%20the%20result%20of%20infinite%20recursion.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOverview%3A%3C%2FP%3E%3COL%3E%3CLI%3EMicrosoft%20publishes%20the%20module%26nbsp%3B%3CEM%3EDNSClient%3C%2FEM%3E%20which%20contains%20the%20function%20%3CEM%3EResolve-DnsName%3C%2FEM%3E.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%3CLI%3EMicrosoft%20also%20publishes%20the%20module%20%3CEM%3ENetTCPIP%3C%2FEM%3E%3CSPAN%3E%2C%20which%20contains%20the%20function%26nbsp%3B%3C%2FSPAN%3E%3CEM%3ETest-NetConnection.%3C%2FEM%3E%3COL%3E%3CLI%3E%3CEM%3ETest-NetConnection%3C%2FEM%3E%3CSPAN%3E%20is%20an%20advanced%20function%20(not%20a%20cmdlet)%2C%20thus%20allowing%20me%20to%20debug%20it.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3CLI%3E%3CEM%3ETest-NetConnection%3C%2FEM%3E%3CSPAN%3E%20eventually%20calls%20%3C%2FSPAN%3E%3CEM%3EResolve-DnsName.%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%3CLI%3EMicrosoft%20%3CEM%3Ealso%3C%2FEM%3E%3CSPAN%3E%20publishes%20the%20module%20%3C%2FSPAN%3E%3CEM%3EMicrosoft.SME.AzureCenter%26nbsp%3B%3C%2FEM%3E%3CSPAN%3Eby%20way%20of%20the%20Windows%20Admin%20Center.%20This%20module%20is%20used%20by%20the%20WAC%20to%20interface%20with%20servers.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CEM%3E%3CSPAN%3EMicrosoft.SME.AzureCenter%3C%2FSPAN%3E%3C%2FEM%3E%3CSPAN%3E%20contains%20an%20advanced%20function%20%3CEM%3EResolve-DnsName%3C%2FEM%3E%26nbsp%3Bthat%20poorly%20wraps%20%3CEM%3EDNSClient%5CResolve-DnsName%3C%2FEM%3E.%26nbsp%3B%3C%2FSPAN%3E%3COL%3E%3CLI%3E%3CSPAN%3E%3CEM%3EMicrosoft.SME.AzureCenter%5CResolve-DnsName%3C%2FEM%3E%20returns%20a%20hashtable%26nbsp%3B%40%7Bsucceeded%20%3D%20%5Btrue%7Cfalse%5D%7D%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EThe%20version%20of%20%3CEM%3EMicrosoft.Sme.AzureCenter%5CResolve-DnsName%20%3C%2FEM%3Ecalls%20%3CEM%3EResolve-DnsName%26nbsp%3B%3C%2FEM%3Ewith%20the%20intention%20of%20using%20%3CEM%3EDNSClient%5CResolve-DnsName%2C%26nbsp%3B%3C%2FEM%3Ebut%20because%20of%20the%20clobbering%2C%20it%20sometimes%20end%20up%20calling%20itself.%20Thus%2C%20%3CEM%3EMicrosoft.SME.AzureCenter%5CResolve-DnsName%3C%2FEM%3E%20ends%20up%20calling%26nbsp%3B%3CEM%3EMicrosoft.SME.AzureCenter%5CResolve-DnsName%26nbsp%3B%3C%2FEM%3Erecursively%2C%20infinitely%2C%20until%20a%20depth%20overflow%20bug%20occurs%3A%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20script%20failed%20due%20to%20call%20depth%20overflow.%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(0%3AInt32)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20CallDepthOverflow%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20only%20thing%20I%20do%20not%20understand%20is%20that%20the%20clobbering%20doesn't%20always%20happen.%20On%20some%20servers%2C%20the%20clobbering%20never%20happens%2C%20while%20on%20others%20it%20happens%20consistently.%20All%20servers%20have%20the%20Windows%20Admin%20Center%20modules%20installed%20for%20the%20purposes%20of%20supporting%20management%20via%20the%20WAC%20Gateway.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESolution%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E1.%20Don't%20clobber%20your%20functions.%20Ever.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E2.%20If%20you%20must%20clobber%20your%20functions%2C%20you%20need%20to%20specify%20the%20fully-qualified%20function%20name%20when%20referring%20to%20a%20function%20that%20can%20potentially%20be%20clobbered%2C%20especially%20if%20you%20plan%20on%20calling%20the%20alternate%20version%20of%20the%20function%20inside%20the%20clobbering%20function.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E3.%20Stop%20clobbering%20your%20functions.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

I have encountered a strange issue that was manifesting itself as a depth overflow bug while Invoking Test-NetConnection on a collection of servers. I have identified that this issue I am seeing is ultimately the result of infinite recursion. 

 

Overview:

  1. Microsoft publishes the module DNSClient which contains the function Resolve-DnsName.

  2. Microsoft also publishes the module NetTCPIP, which contains the function Test-NetConnection.
    1. Test-NetConnection is an advanced function (not a cmdlet), thus allowing me to debug it.

  3. Test-NetConnection eventually calls Resolve-DnsName.

  4. Microsoft also publishes the module Microsoft.SME.AzureCenter by way of the Windows Admin Center. This module is used by the WAC to interface with servers.

  5. Microsoft.SME.AzureCenter contains an advanced function Resolve-DnsName that poorly wraps DNSClient\Resolve-DnsName
    1. Microsoft.SME.AzureCenter\Resolve-DnsName returns a hashtable @{succeeded = [true|false]}
  6. The version of Microsoft.Sme.AzureCenter\Resolve-DnsName calls Resolve-DnsName with the intention of using DNSClient\Resolve-DnsName, but because of the clobbering, it sometimes end up calling itself. Thus, Microsoft.SME.AzureCenter\Resolve-DnsName ends up calling Microsoft.SME.AzureCenter\Resolve-DnsName recursively, infinitely, until a depth overflow bug occurs:

    The script failed due to call depth overflow.
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CallDepthOverflow

 

The only thing I do not understand is that the clobbering doesn't always happen. On some servers, the clobbering never happens, while on others it happens consistently. All servers have the Windows Admin Center modules installed for the purposes of supporting management via the WAC Gateway.

 

Solution:

1. Don't clobber your functions. Ever.

2. If you must clobber your functions, you need to specify the fully-qualified function name when referring to a function that can potentially be clobbered, especially if you plan on calling the alternate version of the function inside the clobbering function. 

3. Stop clobbering your functions. 

0 Replies