From: Laurent Bigonville <bigon@debian.org>
To: Stephen Smalley <sds@tycho.nsa.gov>, selinux@vger.kernel.org
Subject: Re: [PATCH] libsemanage: Always set errno to 0 before calling getpwent()
Date: Fri, 4 Jan 2019 16:57:31 +0100 [thread overview]
Message-ID: <3a568434-6d6a-172c-6337-d43ddfb910e1@debian.org> (raw)
In-Reply-To: <91136ae0462be76415705cb8a014d2a49e59aa85.camel@tycho.nsa.gov>
Le 4/01/19 à 16:11, Stephen Smalley a écrit :
> On Wed, 2019-01-02 at 15:30 +0100, Laurent Bigonville wrote:
>> Le 2/01/19 à 14:46, Laurent Bigonville a écrit :
>>> From: Laurent Bigonville <bigon@bigon.be>
>>>
>>> The manpage explicitly states that:
>>>
>>> The getpwent() function returns a pointer to a passwd
>>> structure, or
>>> NULL if there are no more entries or an error occurred. If an
>>> error
>>> occurs, errno is set appropriately. If one wants to check errno
>>> after
>>> the call, it should be set to zero before the call.
>>>
>>> Without this, genhomedircon can wrongly return the following:
>>> libsemanage.get_home_dirs: Error while fetching
>>> users. Returning list so far.
>>>
>>> https://github.com/SELinuxProject/selinux/issues/121
>>>
>>> Signed-off-by: Laurent Bigonville <bigon@bigon.be>
>>> ---
>>> libsemanage/src/genhomedircon.c | 13 ++++++++++---
>>> 1 file changed, 10 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/libsemanage/src/genhomedircon.c
>>> b/libsemanage/src/genhomedircon.c
>>> index 3e61b510..591941fb 100644
>>> --- a/libsemanage/src/genhomedircon.c
>>> +++ b/libsemanage/src/genhomedircon.c
>>> @@ -361,7 +361,11 @@ static semanage_list_t
>>> *get_home_dirs(genhomedircon_settings_t * s)
>>>
>>> errno = 0;
>>> setpwent();
>>> - while ((pwbuf = getpwent()) != NULL) {
>>> + while (1) {
>>> + errno = 0;
>>> + pwbuf = getpwent();
>>> + if (pwbuf == NULL)
>>> + break;
>>> if (pwbuf->pw_uid < minuid || pwbuf->pw_uid > maxuid)
>>> continue;
>>> if (!semanage_list_find(shells, pwbuf->pw_shell))
>>> @@ -403,7 +407,6 @@ static semanage_list_t
>>> *get_home_dirs(genhomedircon_settings_t * s)
>>> }
>>> free(path);
>>> path = NULL;
>>> - errno = 0;
>> Actually I'm wondering if this shouldn't stay there
> Why?
According to strdup() manpage, it can also change errno, isn't there a
risk that errno is changed to an non-zero value and then causing the
warning below to be printed?
>
>>> }
>>>
>>> if (errno) {
>>> @@ -1101,7 +1104,11 @@ static int
>>> get_group_users(genhomedircon_settings_t * s,
>>> }
>>>
>>> setpwent();
>>> - while ((pw = getpwent()) != NULL) {
>>> + while (1) {
>>> + errno = 0;
>>> + pw = getpwent();
>>> + if (pw == NULL)
>>> + break;
>>> // skip users who also have this group as their
>>> // primary group
>>> if (lfind(pw->pw_name, group->gr_mem, &nmembers,
next prev parent reply other threads:[~2019-01-04 15:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-02 13:46 [PATCH] libsemanage: Always set errno to 0 before calling getpwent() Laurent Bigonville
2019-01-02 14:30 ` Laurent Bigonville
2019-01-04 15:11 ` Stephen Smalley
2019-01-04 15:57 ` Laurent Bigonville [this message]
2019-01-04 16:09 ` Stephen Smalley
2019-01-05 15:35 ` Nicolas Iooss
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=3a568434-6d6a-172c-6337-d43ddfb910e1@debian.org \
--to=bigon@debian.org \
--cc=sds@tycho.nsa.gov \
--cc=selinux@vger.kernel.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: link
Be 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 NNTP newsgroup(s).