This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Manual update for get.*_r functions


>>>>> Mark Kettenis writes:

Mark>    From: Ulrich Drepper <drepper@cygnus.com>
Mark>    Date: 30 Jun 1999 12:47:26 -0700

Mark>    Andreas Jaeger <aj@arthur.rhein-neckar.de> writes:

>> I've checked POSIX and my understanding of POSIX is that the check for 
>> NULL is necessary.

Mark>    POSIX says:

Mark> 	   If successful, the getpwuid_r() and getpwnam_r() functions shall
Mark> 	   return zero.  Otherwise, an error number shall be returned to
Mark> 	   indicate the error.


Mark>    I.e., the return value is != 0 in all error cases and no found entry
Mark>    is an error case.

Mark> Yep, but Andreas is talking about gethostbyname_r().  The case he
Mark> illustrates with his example is the case where gethostbyname() sets
Mark> h_errno to HOST_NOT_FOUND, but errno is not set.  Therefore,
Mark> gethostbyname_r() returns 0 and stores HOST_NOT_FOUND in h_errnop.  So
Mark> instead of checking both the return value and the value stored in
Mark> h_errnop, Andreas suggests to check the result pointer.

Please note that this is a real life example - it's from inet/rcmd.c.
There we only check the return value of gethostbyname_r and access the
result pointer if the return value is 0 without checking h_errnop
which leads to a segmentation fault.

Mark> AFAIK gethostbyname_r() is not standardized by POSIX.  If you look at
Mark> the code in bind 8.2 (src/include/netdb.h) you see that there are
Mark> two flavours of the various getXXbyYY_r functions.  Solaris and BSDI
Mark> return a pointer to the resul buffer on success (and NULL on some sort
Mark> of failure, which sets errno or stores something in h_errnop).  HPUX
Mark> and OSF return -1 on error and use a special data structure to
Mark> guarantee thread-safety.

gethostbyname_r is indeed not standardized but getpwuid_r and
getpwnam_r are.  IMHO we've got to deal (and document!) the following
issues:
- what happens if getpwuid_r can't find a user.  Is an error number
  returned or not?  Is our behaviour conforming with POSIX?
- how should gethostbyname_r work if no host is found?  Should it
  follow the same semantics as getpwuid_r or not?

Sorry for the confusion but IMO those issues are closely related.

Andreas
-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]