All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Kukuk <kukuk@suse.de>
To: selinux@tycho.nsa.gov
Subject: Re: [patch] Change libselinux to use getpwnam_r
Date: Wed, 14 Jan 2004 09:38:00 +0100	[thread overview]
Message-ID: <20040114083800.GA7603@suse.de> (raw)
In-Reply-To: <1074008488.13586.20.camel@moss-spartans.epoch.ncsc.mil>

On Tue, Jan 13, Stephen Smalley wrote:

> The attached patch against libselinux-1.4 changes it to use getpwnam_r
> internally instead of getpwnam, so that it doesn't clobber any existing
> pwd struct previously obtained by the caller.  This showed up as an
> issue for the selinux-enabled gdm.  It doesn't appear to affect login or
> sshd, since they make a copy of the pwd struct themselves.

> +       buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
> +       if (buflen < 0)
> +               return -1;
> +       buf = malloc(buflen);
> +       if (!buf)
> +               return -1;
> +       retval = getpwnam_r (user, pwd, buf, buflen, &pwd );
> +        if (retval < 0 || !pwd) {
> +               free(buf);
> +               return -1;
>          }

While _SC_GETPW_R_SIZE_MAX should return the max. size getpwnam_r
needs for a buffer, in reallity this is often not enough. There is
no limit, how long a line in /etc/passwd can be.
So a better way is:

while (getpwnam_r (user, pwd, buf, buflen, &pwd) != 0
         && errno == ERANGE)
    {
      errno = 0;
      buflen *= 2;
      buf = realloc (buf, buflen);
    }


 Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE Linux AG        Maxfeldstr. 5                 D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2004-01-14  8:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-13 15:41 [patch] Change libselinux to use getpwnam_r Stephen Smalley
2004-01-14  8:38 ` Thorsten Kukuk [this message]
2004-01-14 14:12   ` Stephen Smalley

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=20040114083800.GA7603@suse.de \
    --to=kukuk@suse.de \
    --cc=selinux@tycho.nsa.gov \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.