Support gethostbyname_r_ERANGE.
authorYabin Cui <yabinc@google.com>
Fri, 19 Dec 2014 18:10:04 +0000 (10:10 -0800)
committerYabin Cui <yabinc@google.com>
Fri, 19 Dec 2014 22:11:29 +0000 (14:11 -0800)
Bug: 18802601
Change-Id: Iaa64921e96f91e330f1845c5399ee8aba39d9c10

libc/dns/gethnamaddr.c
libc/dns/net/nsdispatch.c
libc/dns/net/sethostent.c

index 63a6a60d3e218f4f7d6bbe1ba5cac7cd6844a302..8f5800a434460f70a0d14965eb6b371c16613eb9 100644 (file)
@@ -1208,7 +1208,7 @@ _dns_gethtbyname(void *rv, void *cb_data, va_list ap)
        free(buf);
        __res_put_state(res);
        if (hp == NULL)
        free(buf);
        __res_put_state(res);
        if (hp == NULL)
-               switch (h_errno) {
+               switch (*info->he) {
                case HOST_NOT_FOUND:
                        return NS_NOTFOUND;
                case TRY_AGAIN:
                case HOST_NOT_FOUND:
                        return NS_NOTFOUND;
                case TRY_AGAIN:
@@ -1326,6 +1326,7 @@ _dns_gethtbyaddr(void *rv, void   *cb_data, va_list ap)
        *info->he = NETDB_SUCCESS;
        return NS_SUCCESS;
 nospc:
        *info->he = NETDB_SUCCESS;
        return NS_SUCCESS;
 nospc:
+       errno = ENOSPC;
        *info->he = NETDB_INTERNAL;
        return NS_UNAVAIL;
 }
        *info->he = NETDB_INTERNAL;
        return NS_UNAVAIL;
 }
index fb6d8f6ab0ee4949d405e7dd87e90b5f09c360cd..d025592a0473a101d9b05e929d91f64dba83e497 100644 (file)
@@ -71,6 +71,7 @@
 #include <sys/cdefs.h>
 
 #include <assert.h>
 #include <sys/cdefs.h>
 
 #include <assert.h>
+#include <errno.h>
 #include <nsswitch.h>
 #include <stdarg.h>
 #include <strings.h>
 #include <nsswitch.h>
 #include <stdarg.h>
 #include <strings.h>
@@ -133,6 +134,10 @@ nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
                                continue;
                        if (result & srclist[i].flags)
                                break;
                                continue;
                        if (result & srclist[i].flags)
                                break;
+                       /* Stop trying next resolver when there is a memory space fatal error. */
+                       if ((result & NS_UNAVAIL) != 0 && errno == ENOSPC) {
+                         break;
+                       }
                }
        }
        result &= NS_STATUSMASK;        /* clear private flags in result */
                }
        }
        result &= NS_STATUSMASK;        /* clear private flags in result */
index f501c8b5abc1f6e77f12f079df10bf1722bcf66a..916421e3329e2220ff86436e2e4de30043d0ad5a 100644 (file)
@@ -116,7 +116,9 @@ _hf_gethtbyname(void *rv, void *cb_data, va_list ap)
        hp = _hf_gethtbyname2(name, af, info);
 #endif
        if (hp == NULL) {
        hp = _hf_gethtbyname2(name, af, info);
 #endif
        if (hp == NULL) {
-               *info->he = HOST_NOT_FOUND;
+               if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
+                       return NS_UNAVAIL;
+               }
                return NS_NOTFOUND;
        }
        return NS_SUCCESS;
                return NS_NOTFOUND;
        }
        return NS_SUCCESS;
@@ -159,8 +161,12 @@ _hf_gethtbyname2(const char *name, int af, struct getnamaddr *info)
 
                hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen,
                    info->he);
 
                hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen,
                    info->he);
-               if (hp == NULL)
+               if (hp == NULL) {
+                       if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
+                               goto nospc;
+                       }
                        break;
                        break;
+               }
 
                if (strcasecmp(hp->h_name, name) != 0) {
                        char **cp;
 
                if (strcasecmp(hp->h_name, name) != 0) {
                        char **cp;
@@ -259,6 +265,9 @@ _hf_gethtbyaddr(void *rv, void *cb_data, va_list ap)
        endhostent_r(&hf);
 
        if (hp == NULL) {
        endhostent_r(&hf);
 
        if (hp == NULL) {
+               if (errno == ENOSPC) {
+                       return NS_UNAVAIL;
+               }
                *info->he = HOST_NOT_FOUND;
                return NS_NOTFOUND;
        }
                *info->he = HOST_NOT_FOUND;
                return NS_NOTFOUND;
        }