lists.arthurdejong.org
RSS feed

Re: Incorrect service port handling in nss/services.c

[Date Prev][Date Next] [Thread Prev][Thread Next]

Re: Incorrect service port handling in nss/services.c




Thank you for the clarification. I think I am confused by the read_servent routine under nss/services.c:

static enum nss_status read_servent(
       TFILE *fp,struct servent *result,
       char *buffer,size_t buflen,int *errnop)
{
  ...
 /* store port number in network byte order */
 READ_TYPE(fp,tmpint32,int32_t);
 result->s_port=ntohs((uint16_t)tmpint32); <---
 ...
 return NSS_STATUS_SUCCESS;
}

The comment mentioned that network byte order is used to store port number. But "ntohs" is called for s_port, which seems to do the opposite.
PADL implementation uses "htons", instead.

Thanks again.

Ted C. Cheng
tedcheng@symas.com


----- Original Message ----- From: "Arthur de Jong" <arthur@arthurdejong.org>
To: "nss-pam-ldapd-users" <nss-pam-ldapd-users@lists.arthurdejong.org>
Sent: Monday, July 26, 2010 1:24 PM
Subject: Re: Incorrect service port handling in nss/services.c


On Mon, 2010-07-26 at 11:50 -0700, Ted C. Cheng wrote:
Please find attached source code for testgetservbyname.c.

I'm afraid the problem is in your test code. Attached is a patch.

The getservbyname(3) manual page says about s_port: "The port number for
the service given in network byte order." so any client application
should use ntohs() before use. Check it with an entry from /etc/services
(e.g. www).

With the patch it works on Debian Gnu/Linux squeeze (Glibc 2.11.2 on
i386 but it was originally developed and tested on Glibc 2.3.2). Glibc
has been known [1] to change byte order around for some internals but I
don't think that is the case here.

Anyway, thanks for testing nss-pam-ldapd.

[1] http://sourceware.org/ml/glibc-cvs/2009-q3/msg00000.html

--
-- arthur - arthur@arthurdejong.org - http://arthurdejong.org --



--------------------------------------------------------------------------------


--
To unsubscribe send an email to
nss-pam-ldapd-users-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-users

--
To unsubscribe send an email to
nss-pam-ldapd-users-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-users