/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
/* 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;
}
cur += sprintf(&hostlist[cur], "%s:%hd", host, port);
}
+add_size:;
p += size;
}
}