Bug 137199 - getXXXent_r functions don't set errno=ENOENT at end of data
Summary: getXXXent_r functions don't set errno=ENOENT at end of data
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc   
(Show other bugs)
Version: 3
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2004-10-26 17:06 UTC by Mike Bird
Modified: 2007-11-30 22:10 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-26 20:22:39 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Sample getgrent_r tester which demonstrates glibc bug. (1.00 KB, text/plain)
2004-10-26 17:08 UTC, Mike Bird
no flags Details

Description Mike Bird 2004-10-26 17:06:26 UTC
Description of problem:

The getXXXent_r functions return ENOENT at end of data but they leave
errno unchanged.  This is a particular problem if an earlier
getXXXent_r had set errno to ERANGE.  Code sees status!=0 and
errno=ERANGE and tries again with a larger buffer until memory is
exhausted.  Perl's getXXXent functions are affected by this, which
explains why they blow up on large systems but not test systems. 
WebMin is a popular system administration tool which blows up as a
result of this.

Google reveals a number of reports for which this bug is the
explanation.  The relevant maintainers seem to have rejected the bug
reports as unreproducible because they didn't have long enough lines
in their /etc/group.

Version-Release number of selected component (if applicable):

Reproduced in glibc-2.3.2-27.9.7, glibc-2.3.3-27, and glibc-2.3.3-53.

How reproducible:


Steps to Reproduce:
1. Run attached program.
Actual results:

At end of /etc/group it keeps retrying with ever larger buffer sizes.

Expected results:

Should have set errno=ENOENT when it returned ENOENT, i.e. as soon as
it had a large enough buffer.

Additional info:

Comment 1 Mike Bird 2004-10-26 17:08:17 UTC
Created attachment 105803 [details]
Sample getgrent_r tester which demonstrates glibc bug.

Comment 2 Jakub Jelinek 2004-10-26 20:22:39 UTC
That is not a glibc bug.  errno is not defined after getgrent_r
man getgrent_r has:
       On  success,  these  functions  return 0 and *gbufp is a pointer to the
       struct group.  On error, these functions  return  an  error  value  and
       *gbufp is NULL.
No words about errno being set.
POSIX doesn't cover getgrent_r, but getgrnam_r is similar enough and
covered by POSIX:
     ^[TSF] [Option Start] If successful, the getgrnam_r() function shall return zero; otherwise, an error number shall be
     returned to indicate the error. [Option End]

So, your testcase should be checking } else if (rc == ENOENT) { ... } else if (rc != ERANGE) { ... } else { ... }

Comment 3 Mike Bird 2004-10-26 20:34:21 UTC
Does this mean that it is a bug that getgrent_r clobbers errno without
warning in the ERANGE case?

Comment 4 Jakub Jelinek 2004-10-26 20:46:48 UTC
errno is undefined after getgrent_r call.
The value of errno should only be examined when it is
indicated to be valid by a function's return value.
The setting of errno after a successful call to a function is unspecified unless the description of that function specifies that errno shall not be
doesn't indicate errno is not modified, nor claims errno is always set,
nor does have any return value that indicates errno is valid.
Therefore after you call getgrnam_r errno should not be examined.

getgrent_r is not covered by POSIX, but behaves in this regard like
getgrnam_r (and man getgrent_r describes this).

Comment 5 Mike Bird 2004-10-26 21:02:06 UTC
PERL bug report updated with your information:


Note You need to log in before you can comment on or make changes to this bug.