You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Joe Orton <jo...@redhat.com> on 2005/07/19 12:11:26 UTC

Re: svn commit: r219635 - in /apr/apr/trunk: CHANGES user/unix/groupinfo.c user/unix/userinfo.c

On Tue, Jul 19, 2005 at 09:38:49AM -0000, Paul Querna wrote:
> Author: pquerna
> Date: Tue Jul 19 02:38:36 2005
> New Revision: 219635
> 
> URL: http://svn.apache.org/viewcvs?rev=219635&view=rev
> Log:
> These functions can return no-error, but still contain a NULL entry, on some crazy unix that some people use called Linux.

Interestingly the behaviour is correct by a literal interpretation of 
POSIX, which distinguishes the "not found" case from "error" cases.  But 
in any case errno is not used to return errors for the _r functions, so 
this is likely to just propagate the confusion by returning APR_SUCCESS.

I'd guess the correct fix is something like the below: I'd like to do 
some more testing first...

Index: user/unix/userinfo.c
===================================================================
--- user/unix/userinfo.c	(revision 219637)
+++ user/unix/userinfo.c	(working copy)
@@ -114,13 +114,20 @@
 #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWUID_R)
     struct passwd pwd;
     char pwbuf[PWBUF_SIZE];
+    apr_status_t rv;
 
-    if (getpwuid_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw) || pw == NULL) {
+    rv = getpwuid_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw);
+    if (rv) {
+        return rv;
+    }
+    if (pw == NULL) {
+        return APR_ENOENT;
+    }
 #else
     if ((pw = getpwuid(userid)) == NULL) {
-#endif
         return errno;
     }
+#endif
     *username = apr_pstrdup(p, pw->pw_name);
     return APR_SUCCESS;
 }