This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nscd/15139] getpwuid_r does not return ERANGE consistently
- From: "carlos at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 13 Feb 2013 16:26:58 +0000
- Subject: [Bug nscd/15139] getpwuid_r does not return ERANGE consistently
- Auto-submitted: auto-generated
- References: <bug-15139-131@http.sourceware.org/bugzilla/>
http://sourceware.org/bugzilla/show_bug.cgi?id=15139
Carlos O'Donell <carlos at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |WAITING
CC| |carlos at redhat dot com
--- Comment #1 from Carlos O'Donell <carlos at redhat dot com> 2013-02-13 16:26:58 UTC ---
Thomas,
The function is allowed to return ERANGE at *any* time and the user application
must grow the buffer. The fault is with Sigar here.
However, there is an orthogonal issue in that sysconf (_SC_GETPW_R_SIZE_MAX)
returns a static 1024 on Linux and that is technically too small for some
results. It is my opinion that it should return -1, indicating that there is no
limit and that it is up to the user to choose a reasonably large value and to
watch out for ERANGE.
If anything the bug is that sysconf (_SC_GETPW_R_SIZE_MAX) returns a limit,
that when used, is actually too small.
The correct solution on the glibc side is likely going to be to return -1 for
sysconf (_SC_GETPW_R_SIZE_MAX), and the fix on the Sigar side is going to be to
be to do something like this (completely off the top of my head with no
testing):
/* sysconf(_SC_GET{PW,GR}_R_SIZE_MAX) == -1, choose a reasonable buffer size.
*/
#define R_SIZE_MAX 8192 /* Multiple of 2*R_SIZE_INIT */
#define R_SIZE_INIT 1024
...
# ifdef HAVE_GETPWUID_R
struct passwd pwbuf;
int saved_errno;
char *buffer;
/* Allocate an initial buffer. */
size_t buflen = R_SIZE_INIT;
buffer = (char *) malloc (buflen);
if (buffer == NULL)
return errno;
do {
if (getpwuid_r(uid, &pwbuf, buffer, sizeof(buffer), &pw) != 0) {
saved_errno = errno;
/* We handle ERANGE, but anything else return as an error. */
if (errno != ERANGE)
return errno;
/* Double the buffer size and try again. */
buflen = buflen * 2;
if (buflen > R_SIZE_MAX)
/* We hit our own internal limit. Return artificial ENOMEM. */
return ENOMEM;
buffer = (char *) realloc (buffer, buflen);
if (buffer == NULL)
return errno;
}
if (!pw) {
return ENOENT;
}
} while (saved_errno == ERANGE)
# else
...
Does that make sense?
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.