On Tue, 18 Mar 2008, Hallvard B Furuseth wrote:
> Thanks. Fixed os-ip.c in CVS HEAD (but see below).
>
> rein(a)basefarm.no writes:
>> libraries/libldap/os-ip.c casts the argument to htons() to a short, it
>> should be an explicit unsigned short. This causes the use of high
>> port numbers to fail on systems where shorts are signed by default.
>
> short is signed by definition.
More the good reason why it should be cast to an unsigned then, as that is
what htons() expects.
> Do you have a test case? As far as I can tell it broke if the caller
> had the same error: storing a port number in a short, and passing that
> short to ldap_init() & co. And it broke on systems with 16-bit int, if
> there are such system around where OpenLDAP compiles in the first place.
>
> If we care about systems with 16-bit int, the proper fix is to also make
> LDAPURLDesc.lud_port and various 'port' function parameters unsigned. I
> have no idea if there is such a system which can even compile OpenLDAP
> though.
No, I don't have a test case. This is a fairly insignificant bugfix I
commited to our copy of the source six years ago and has never gotten
around to report back (sorry for that).
The exact details I'm afraid I have forgotten a long time ago, and I
generally find that figuring too much about the gory storage details of
signed vs. unsigned, and big/little-endianness only gives me a slight
headache ;-) But it definitely wasn't any 16-bit systems, and I can't
see any reason why anyone should worry about those anymore.. It was most
likely on a 64bit sparc system using sun's compiler, but it might have
been linux/gcc on a 32bit i686 for all I remember now.
Rein