public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "carlos at redhat dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug nscd/15139] getpwuid_r does not return ERANGE consistently Date: Wed, 13 Feb 2013 16:27:00 -0000 [thread overview] Message-ID: <bug-15139-131-PwU1EWoVkW@http.sourceware.org/bugzilla/> (raw) In-Reply-To: <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.
next prev parent reply other threads:[~2013-02-13 16:27 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-02-13 11:13 [Bug nscd/15139] New: " tsegismo at redhat dot com 2013-02-13 16:27 ` carlos at redhat dot com [this message] 2013-02-13 16:43 ` [Bug nscd/15139] " tsegismo at redhat dot com 2013-02-13 18:58 ` carlos at redhat dot com 2014-06-13 18:50 ` fweimer at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-15139-131-PwU1EWoVkW@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).