This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Calling properly getpwuid_r
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>, Roland McGrath <roland at hack dot frob dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: Thomas Segismont <tsegismo at redhat dot com>, libc-help at sourceware dot org
- Date: Wed, 13 Feb 2013 11:01:50 -0500
- Subject: Re: Calling properly getpwuid_r
- References: <511A62AA.8020801@redhat.com><CAAHN_R3FRrGBzH97iEPQ4ntddehCxxy=pKqtqkNpc-4PdwCdyQ@mail.gmail.com>
On Tue, Feb 12, 2013 at 10:47 AM, Siddhesh Poyarekar
<siddhesh.poyarekar@gmail.com> wrote:
> On 12 February 2013 21:11, Thomas Segismont <tsegismo@redhat.com> wrote:
>> On the libc manual, there is an example on how to call gethostbyname_r:
>> http://www.gnu.org/software/libc/manual/html_node/Host-Names.html
>>
>> As getpwuid_r seems to be backed by the same code in getXXbyYY_r.c, is it
>> also recommended to call it in a while loop to deal with erange errors?
>
> Yes.
>
>> Is there a particular reason for this?
>
> The string fields in the struct paswd returned are stored in the
> caller-supplied buffer. The call will return ERANGE if the buffer is
> not large enough.
So this question is more for Roland and Joseph.
We have _SC_GETPW_R_SIZE_MAX which one can use with sysconf to get the
system limit for use when allocating a buffer large enough to pass to
getpwuid_r.
The problem I see is that _SC_GETPW_R_SIZE_MAX is NSS_BUFLEN_PASSWD or
1024 on Linux.
This buffer size is way to small for some applications, which causes
ERANGE to be returned even though you allocated a buffer that is
technically as big as you're allowed.
What gives? Is it a bug that _SC_GETPW_R_SIZE_MAX is 1024, should it be -1?
Cheers,
Carlos.