Microsoft KB Archive/317892

= BUG: gethostbyname May Corrupt Memory for DNS Name with More Than 15 IP Addresses Assigned =

PSS ID Number: 317892

Article Last Modified on 11/5/2003

-

The information in this article applies to:


 * Microsoft Windows CE Platform SDK for Pocket PC

-



This article was previously published under Q317892



SYMPTOMS
Program memory may be corrupted when the following conditions exist:
 * You call the gethostbyname function to resolve the domain name system (DNS) name of a host.
 * More than 15 IP addresses are assigned to the host.
 * The results of an earlier call to the gethostbyname have already been cached in the registry-based Domain Name System (DNS) cache.



CAUSE
This behavior occurs because the code reads DNS cache entries from the registry and uses a buffer that holds a maximum of 15 IP addresses.



RESOLUTION
To work around this issue, follow these steps:
 * 1) After you call gethostbyname, count the number of IP addresses that are returned.
 * 2) If more than 15 IP addresses are returned, delete the DNS cache entry that was just created by gethostbyname.

The following sample code demonstrates the workaround:

char *pszHost = &quot;host.domain.com&quot;; hostent *hostp;

if ((hostp = gethostbyname(pszHost)) != NULL) { char **p = hostp->h_addr_list; int len = 0;

while (*p != 0) { p++; len++; }

if (len > 15) { TCHAR szRegKey[MAX_PATH + 1]; TCHAR szName[MAX_PATH + 1];

memset(szName, 0, MAX_PATH + 1); mbstowcs(szName, hostp->h_name, MAX_PATH); wsprintf(szRegKey, L&quot;Comm\\Tcpip\\Hosts\\%s&quot;, szName); RegDeleteKey(HKEY_LOCAL_MACHINE, szRegKey); } }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
This problem does not occur on Windows CE version 3.0-based devices (for example, Handheld PC 2000 or Microsoft Pocket PC 2002) because the DNS cache design is not registry-based.

Keywords: kbbug kbnofix KB317892

Technology: kbAudDeveloper kbPocketSearch kbSDKSearch kbWinCESDKPalmsizePC kbWinCESDKSearch kbWinCESearch

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.