diff options
author | Tomas Mraz <tmraz@fedoraproject.org> | 2019-08-12 16:43:59 +0200 |
---|---|---|
committer | Tomas Mraz <tmraz@fedoraproject.org> | 2019-08-13 11:44:45 +0200 |
commit | 8ab99435c0c6e993af090759fea8879bcabaae6c (patch) | |
tree | 038cbee4f310324d6df9ea575bb5be765ccbb434 | |
parent | 63be1415bf6c3b73bb0a4971e1ffeb5923269b7c (diff) |
BIO_lookup_ex: Do not retry on EAI_MEMORY
We should not retry on EAI_MEMORY as that error is most probably
fatal and not depending on AI_ADDRCONFIG hint.
Also report the error from the first call if the second call fails
as that one would be most probably the more interesting one.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9535)
(cherry picked from commit 91cb81d40a8102c3d8667629661be8d6937db82b)
-rw-r--r-- | crypto/bio/b_addr.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c index 10738daacb..dd5008e636 100644 --- a/crypto/bio/b_addr.c +++ b/crypto/bio/b_addr.c @@ -675,7 +675,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type, if (1) { #ifdef AI_PASSIVE - int gai_ret = 0; + int gai_ret = 0, old_ret = 0; struct addrinfo hints; memset(&hints, 0, sizeof(hints)); @@ -683,12 +683,12 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type, hints.ai_family = family; hints.ai_socktype = socktype; hints.ai_protocol = protocol; -#ifdef AI_ADDRCONFIG -#ifdef AF_UNSPEC +# ifdef AI_ADDRCONFIG +# ifdef AF_UNSPEC if (family == AF_UNSPEC) -#endif +# endif hints.ai_flags |= AI_ADDRCONFIG; -#endif +# endif if (lookup_type == BIO_LOOKUP_SERVER) hints.ai_flags |= AI_PASSIVE; @@ -704,6 +704,11 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type, BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB); break; # endif +# ifdef EAI_MEMORY + case EAI_MEMORY: + BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE); + break; +# endif case 0: ret = 1; /* Success */ break; @@ -712,11 +717,12 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type, if (hints.ai_flags & AI_ADDRCONFIG) { hints.ai_flags &= ~AI_ADDRCONFIG; hints.ai_flags |= AI_NUMERICHOST; + old_ret = gai_ret; goto retry; } # endif BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB); - ERR_add_error_data(1, gai_strerror(gai_ret)); + ERR_add_error_data(1, gai_strerror(old_ret ? old_ret : gai_ret)); break; } } else { |