From a694f07970127dc45906a9d35ae2d1f588450e1d Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 7 Feb 2005 15:27:40 +0000 Subject: * net.cc (cygwin_gethostbyname): Be more picky about what's a numeric address string, and use tls in that case too. --- winsup/cygwin/net.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'winsup/cygwin/net.cc') diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index baa96bb..4e65bfa 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -936,17 +936,19 @@ cygwin_gethostname (char *name, size_t len) extern "C" struct hostent * cygwin_gethostbyname (const char *name) { - static unsigned char tmp_addr[4]; - static struct hostent tmp; - static char *tmp_aliases[1]; - static char *tmp_addr_list[2]; - static int a, b, c, d; + unsigned char tmp_addr[4]; + struct hostent tmp, *h; + char *tmp_aliases[1] = {0}; + char *tmp_addr_list[2] = {0,0}; + unsigned int a, b, c, d; + char dummy; sig_dispatch_pending (); if (check_null_str_errno (name)) return NULL; - if (sscanf (name, "%d.%d.%d.%d", &a, &b, &c, &d) == 4) + if (sscanf (name, "%u.%u.%u.%u%c", &a, &b, &c, &d, &dummy) == 4 + && a < 256 && b < 256 && c < 256 && d < 256) { /* In case you don't have DNS, at least x.x.x.x still works */ memset (&tmp, 0, sizeof (tmp)); @@ -960,11 +962,13 @@ cygwin_gethostbyname (const char *name) tmp.h_addrtype = 2; tmp.h_length = 4; tmp.h_addr_list = tmp_addr_list; - return &tmp; + h = &tmp; } + else + h = gethostbyname (name); + + _my_tls.locals.hostent_buf = (hostent *) dup_ent (_my_tls.locals.hostent_buf, h, is_hostent); - _my_tls.locals.hostent_buf = (hostent *) dup_ent (_my_tls.locals.hostent_buf, gethostbyname (name), - is_hostent); if (!_my_tls.locals.hostent_buf) { debug_printf ("name %s", name); -- cgit v1.1