Forum Discussion

thesmall's avatar
thesmall
Copper Contributor
Aug 24, 2020

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

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. 

No RepliesBe the first to reply

Resources