You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by pq...@apache.org on 2005/07/19 11:38:49 UTC

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

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.

PR: 34053

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/user/unix/groupinfo.c
    apr/apr/trunk/user/unix/userinfo.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=219635&r1=219634&r2=219635&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Tue Jul 19 02:38:36 2005
@@ -1,5 +1,8 @@
 Changes for APR 1.2.0
 
+  *) If getpwuid_r or getgrgid_r set their results to NULL, it is an error.
+     PR 34053. [Paul Querna]
+
   *) Switch to lazy initialization of the pollset that's used within
      apr_file_t on platforms where apr_wait_for_io_or_timeout() doesn't
      use poll(2).  (This fixes a performance problem observed in httpd-2.x

Modified: apr/apr/trunk/user/unix/groupinfo.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/user/unix/groupinfo.c?rev=219635&r1=219634&r2=219635&view=diff
==============================================================================
--- apr/apr/trunk/user/unix/groupinfo.c (original)
+++ apr/apr/trunk/user/unix/groupinfo.c Tue Jul 19 02:38:36 2005
@@ -37,7 +37,7 @@
     struct group grp;
     char grbuf[512];
 
-    if (getgrgid_r(groupid, &grp, grbuf, sizeof(grbuf), &gr)) {
+    if (getgrgid_r(groupid, &grp, grbuf, sizeof(grbuf), &gr) || gr == NULL) {
 #else
     if ((gr = getgrgid(groupid)) == NULL) {
 #endif

Modified: apr/apr/trunk/user/unix/userinfo.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/user/unix/userinfo.c?rev=219635&r1=219634&r2=219635&view=diff
==============================================================================
--- apr/apr/trunk/user/unix/userinfo.c (original)
+++ apr/apr/trunk/user/unix/userinfo.c Tue Jul 19 02:38:36 2005
@@ -115,7 +115,7 @@
     struct passwd pwd;
     char pwbuf[PWBUF_SIZE];
 
-    if (getpwuid_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw)) {
+    if (getpwuid_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw) || pw == NULL) {
 #else
     if ((pw = getpwuid(userid)) == NULL) {
 #endif



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

Posted by Joe Orton <jo...@redhat.com>.
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;
 }