Refine login in b_sock.c.
[openssl.git] / crypto / bio / b_sock.c
index 26aa9dc8dabd56c739bdc97228c5d5481a68ffbf..fd45bec3316017384e5600d343a461745a3bd23f 100644 (file)
@@ -640,7 +640,21 @@ int BIO_get_accept_socket(char *host, int bind_mode)
         * note that commonly IPv6 wildchard socket can service
         * IPv4 connections just as well...  */
        memset(&hint,0,sizeof(hint));
-       if (h && strchr(h,':')) hint.ai_family = AF_INET6;
+       if (h)
+               {
+               if (strchr(h,':'))
+                       {
+                       if (h[1]=='\0') h=NULL;
+#ifdef AF_INET6
+                       hint.ai_family = AF_INET6;
+#else
+                       h=NULL;
+#endif
+                       }
+               else if (h[0]=='*' && h[1]=='\0')
+                       h=NULL;
+               }
+
        if ((*getaddrinfo.f)(h,p,&hint,&res)) break;
        server = *res->ai_addr;
        (*freeaddrinfo.f)(res);
@@ -802,10 +816,10 @@ int BIO_accept(int sock, char **addr)
 
        if ((*getnameinfo.f)(&from,sizeof(from),h,sizeof(h),s,sizeof(s),
            NI_NUMERICHOST|NI_NUMERICSERV)) break;
-       l = strlen(h)+strlen(p)+2; if (len<24) len=24;
+       l = strlen(h)+strlen(s)+2; if (len<24) len=24;
        p = *addr;
-       if (p)  p = OPENSSL_realloc(p,l);
-       else    p = OPENSSL_malloc(l);
+       if (p)  { *p = '\0'; p = OPENSSL_realloc(p,l);  }
+       else    { p = OPENSSL_malloc(l);                }
        if (p==NULL)
                {
                BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);