#ifndef OPENSSL_NO_SOCK
#include <openssl/err.h>
#include <openssl/buffer.h>
+#include <internal/thread_once.h>
#include <ctype.h>
CRYPTO_RWLOCK *bio_lookup_lock;
ntohs(BIO_ADDR_rawport(ap)));
}
- if (hostname)
+ if (hostname != NULL)
*hostname = OPENSSL_strdup(host);
- if (service)
+ if (service != NULL)
*service = OPENSSL_strdup(serv);
} else {
#endif
- if (hostname)
+ if (hostname != NULL)
*hostname = OPENSSL_strdup(inet_ntoa(ap->s_in.sin_addr));
- if (service) {
+ if (service != NULL) {
char serv[6]; /* port is 16 bits => max 5 decimal digits */
BIO_snprintf(serv, sizeof(serv), "%d", ntohs(ap->s_in.sin_port));
*service = OPENSSL_strdup(serv);
}
}
+ if ((hostname != NULL && *hostname == NULL)
+ || (service != NULL && *service == NULL)) {
+ if (hostname != NULL) {
+ OPENSSL_free(*hostname);
+ *hostname = NULL;
+ }
+ if (service != NULL) {
+ OPENSSL_free(*service);
+ *service = NULL;
+ }
+ BIOerr(BIO_F_ADDR_STRINGS, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+
return 1;
}
return 1;
}
-static void do_bio_lookup_init(void)
+DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
{
+ OPENSSL_init_crypto(0, NULL);
bio_lookup_lock = CRYPTO_THREAD_lock_new();
+ return bio_lookup_lock != NULL;
}
/*-
struct addrinfo hints;
memset(&hints, 0, sizeof hints);
-# ifdef AI_ADDRCONFIG
- hints.ai_flags = AI_ADDRCONFIG;
-# endif
hints.ai_family = family;
hints.ai_socktype = socktype;
/* Windows doesn't seem to have in_addr_t */
#ifdef OPENSSL_SYS_WINDOWS
static uint32_t he_fallback_address;
- static const uint32_t *he_fallback_addresses[] =
- { &he_fallback_address, NULL };
+ static const char *he_fallback_addresses[] =
+ { (char *)&he_fallback_address, NULL };
#else
static in_addr_t he_fallback_address;
- static const in_addr_t *he_fallback_addresses[] =
- { &he_fallback_address, NULL };
+ static const char *he_fallback_addresses[] =
+ { (char *)&he_fallback_address, NULL };
#endif
static const struct hostent he_fallback =
{ NULL, NULL, AF_INET, sizeof(he_fallback_address),
struct servent se_fallback = { NULL, NULL, 0, NULL };
#endif
- CRYPTO_THREAD_run_once(&bio_lookup_init, do_bio_lookup_init);
+ if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
+ BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
+ ret = 0;
+ goto err;
+ }
CRYPTO_THREAD_write_lock(bio_lookup_lock);
he_fallback_address = INADDR_ANY;