This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gethostbyname/gethostbyaddr patch


The following patch:

    http://www.cygwin.com/ml/cygwin-cvs/2001-q3/msg00100.html

broke gethostbyname() and gethostbyaddr() when the IP address contains
zero components.  For example, my mail server is 24.0.95.227.  When I
connect to it with a Cygwin app, the address actually used is 24.0.0.0.

The root cause is that dup_char_list() does not handle embedded null
characters.  The attached patch is one way to correct this problem.

Jason
Index: net.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/net.cc,v
retrieving revision 1.68
diff -u -p -r1.68 net.cc
--- net.cc	2001/08/22 21:51:48	1.68
+++ net.cc	2001/08/23 19:58:29
@@ -409,6 +409,25 @@ dup_char_list (char **src)
   return dst;
 }
 
+static char **
+dup_addr_list (char **src, unsigned int size)
+{
+  char **dst;
+  int cnt = 0;
+
+  for (char **cl = src; *cl; ++cl)
+    ++cnt;
+  if (!(dst = (char **) calloc (cnt + 1, sizeof *dst)))
+    return NULL;
+  while (cnt-- > 0)
+    {
+      if (!(dst[cnt] = (char *) malloc(size)))
+        return NULL;
+	  memcpy(dst[cnt], src[cnt], size);
+    }
+  return dst;
+}
+
 static void
 free_protoent_ptr (struct protoent *&p)
 {
@@ -1021,7 +1040,8 @@ dup_hostent_ptr (struct hostent *src)
     goto out;
   if (src->h_aliases && !(dst->h_aliases = dup_char_list (src->h_aliases)))
     goto out;
-  if (src->h_addr_list && !(dst->h_addr_list = dup_char_list(src->h_addr_list)))
+  if (src->h_addr_list && !(dst->h_addr_list = dup_addr_list (src->h_addr_list,
+    src->h_length)))
     goto out;
 
   debug_printf ("hostent: copied %s", dst->h_name);
Thu Aug 23 16:00:09 2001  Jason Tishler <jason@tishler.net>

	* net.cc (dup_addr_list): New static function.
	(dup_hostent_ptr): Use dup_addr_list instead of dup_char_list in order
	to handle embedded null characters.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]