This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calling properly getpwuid_r


On Wed, Feb 13, 2013 at 11:01 AM, Carlos O'Donell
<carlos@systemhalted.org> wrote:
> 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?

See:
http://sourceware.org/bugzilla/show_bug.cgi?id=15139

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]