* http.c (connect_server): [_WIN32] actually fill in the sin_addr so we
authorDavid Shaw <dshaw@jabberwocky.com>
Sat, 16 Oct 2004 21:31:36 +0000 (21:31 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Sat, 16 Oct 2004 21:31:36 +0000 (21:31 +0000)
aren't always talking to localhost.  Add some general sanity checking of
parameters learned from gethostbyname().

util/ChangeLog
util/http.c

index 7264d0f..5a20a81 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-16  David Shaw  <dshaw@jabberwocky.com>
+
+       * http.c (connect_server): [_WIN32] actually fill in the sin_addr
+       so we aren't always talking to localhost.  Add some general sanity
+       checking of parameters learned from gethostbyname().
+
 2004-10-15  Werner Koch  <wk@g10code.com>
 
        * vasprintf.c: New.  Taken from gnupg 1.9.
index 7ee088e..e1c3c25 100644 (file)
@@ -780,6 +780,7 @@ connect_server( const char *server, ushort port, unsigned int flags )
 
       addr.sin_family=AF_INET; 
       addr.sin_port=htons(port);
+      memcpy(&addr.sin_addr,&inaddr,sizeof(inaddr));      
 
       if(connect(sock,(struct sockaddr *)&addr,sizeof(addr))==0)
        return sock;
@@ -797,7 +798,6 @@ connect_server( const char *server, ushort port, unsigned int flags )
     {
       /* We're using SRV, so append the tags */
       char srvname[MAXDNAME];
-
       strcpy(srvname,"_hkp._tcp.");
       strncat(srvname,server,MAXDNAME-11);
       srvname[MAXDNAME-1]='\0';
@@ -872,11 +872,23 @@ connect_server( const char *server, ushort port, unsigned int flags )
        }
 
       addr.sin_family=host->h_addrtype;
+      if(addr.sin_family!=AF_INET)
+       {
+         log_error("%s: unknown address family\n",srvlist[srv].target);
+         return -1;
+       }
+
       addr.sin_port=htons(srvlist[srv].port);
 
       /* Try all A records until one responds. */
       while(host->h_addr_list[i])
        {
+         if(host->h_length!=4)
+           {
+             log_error("%s: illegal address length\n",srvlist[srv].target);
+             return -1;
+           }
+
          memcpy(&addr.sin_addr,host->h_addr_list[i],host->h_length);
 
          if(connect(sock,(struct sockaddr *)&addr,sizeof(addr))==0)