develooper Front page | perl.perl5.porters | Postings from September 2011

Re: [perl #98934] set{u,g}id doesn't clear $! on success

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
September 13, 2011 05:30
Subject:
Re: [perl #98934] set{u,g}id doesn't clear $! on success
Message ID:
CAHhgV8hHZLmteu3VA6QK-w-7pb5niKf2PW-LL=6dgYxX=y0ogQ@mail.gmail.com
On Mon, Sep 12, 2011 at 9:50 PM, Chris Adams <cmadams@hiwaay.net> wrote:
> The problem is that is not what the documentation says.  The docs say
> "require a check to $! to detect any possible errors", not "you must
> clear $! first, make your change, then check the results".

Then the documentation should be clarified.

> The underlying problem is that the perl source code doesn't check or
> save the return code from the setregid() call.  Since library calls can
> have unexpected side-effects, perl should handle this internally.

It's an abstraction that leaks like a sieve. If you ask me the obvious
way to deal with this would be to throw an exception on error, but
that will probably require a «use 5.016;». Using a module that does
the right dance still sounds like a better idea though.

> This is highly confusing, and there's really no reason to push this off
> on the people writing perl code.  At a minimum, perl internally could do
> something like:
>
>    if (setregid(gid,-1) == 0)
>        errno = 0;
>
> (and that goes for all the setuid/setgid family of functions).

That might piss off an equal number of users because $! gets
overwritten when they didn't expect it.

> No, I only want to set the real GID here (I'm dropping privs temporarily
> for a check).

Please explain yourself. What does setting the real GID do for you? It
has very little to do with dropping any privileges, temporarily or
permanently.

Leon

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About