X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fdnssrv.c;h=16b15447cac2bfefc717104998aa5b065cb6fb87;hb=7164c4c66215da39f03e353a9c72eba408abddbf;hp=1bf7eb64269c0d2071f204d3ea7ddcc6e96c025f;hpb=f0505795c0c603af495cda608a00f866c9c09abc;p=openldap diff --git a/libraries/libldap/dnssrv.c b/libraries/libldap/dnssrv.c index 1bf7eb6426..16b15447ca 100644 --- a/libraries/libldap/dnssrv.c +++ b/libraries/libldap/dnssrv.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2004 The OpenLDAP Foundation. + * Copyright 1998-2011 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -202,9 +202,7 @@ int ldap_domain2hostlist( } sprintf(request, "_ldap._tcp.%s", domain); -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex); -#endif + LDAP_MUTEX_LOCK(&ldap_int_resolv_mutex); rc = LDAP_UNAVAILABLE; #ifdef NS_HFIXEDSZ @@ -275,8 +273,12 @@ int ldap_domain2hostlist( /* weight = (p[2] << 8) | p[3]; */ port = (p[4] << 8) | p[5]; - buflen = strlen(host) + sizeof(":65355 "); - hostlist = (char *) LDAP_REALLOC(hostlist, cur + buflen); + if ( port == 0 || host[ 0 ] == '\0' ) { + goto add_size; + } + + buflen = strlen(host) + STRLENOF(":65355 "); + hostlist = (char *) LDAP_REALLOC(hostlist, cur + buflen + 1); if (hostlist == NULL) { rc = LDAP_NO_MEMORY; goto out; @@ -285,8 +287,9 @@ int ldap_domain2hostlist( /* not first time around */ hostlist[cur++] = ' '; } - cur += sprintf(&hostlist[cur], "%s:%hd", host, port); + cur += sprintf(&hostlist[cur], "%s:%hu", host, port); } +add_size:; p += size; } } @@ -300,9 +303,7 @@ int ldap_domain2hostlist( *list = hostlist; out: -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex); -#endif + LDAP_MUTEX_UNLOCK(&ldap_int_resolv_mutex); if (request != NULL) { LDAP_FREE(request);