[Date Prev][Date Next] [Chronological] [Thread] [Top]

ldap_connect_to_host failure on Solaris 8 for large port numbers (ITS#1375)



Full_Name: Andreas Mueller
Version: 2.0.15
OS: Solaris 8
URL: 
Submission from: (NULL) (194.230.254.3)


in os-ip.c on line 309, the port number is converted to a string using the
code

	snprintf(serv, sizeof serv, "%d", ntohs(port));

but since the port is an unsigned short, large port numbers like 38989
end up as negative numbers like -26547. This string is nonsensical to the
subsequent getaddrinfo call, at least on Solaris 8, resulting in a failure
of ldap_connect_to_host.

Using "%hu" as format string gives the correct result and allows libldap
to work with large portnumbers. Here is a patch that says the same thing:

*** libraries/libldap/os-ip.c.orig      Sat Oct  6 23:22:20 2001
--- libraries/libldap/os-ip.c   Sat Oct  6 23:22:00 2001
***************
*** 306,312 ****
                hints.ai_family = AF_UNSPEC;
                hints.ai_socktype = SOCK_STREAM;

!               snprintf(serv, sizeof serv, "%d", ntohs(port));
                if ( err = getaddrinfo(host, serv, &hints, &res) ) {
                        osip_debug(ld, "ldap_connect_to_host: getaddrinfo
failed: %s\n",
                                AC_GAI_STRERROR(err), 0, 0);
--- 306,312 ----
                hints.ai_family = AF_UNSPEC;
                hints.ai_socktype = SOCK_STREAM;

!               snprintf(serv, sizeof serv, "%hu", ntohs(port));
                if ( err = getaddrinfo(host, serv, &hints, &res) ) {
                        osip_debug(ld, "ldap_connect_to_host: getaddrinfo
failed: %s\n",
                                AC_GAI_STRERROR(err), 0, 0);

This problem was already present in OpenLDAP 2.0.7.