develooper Front page | perl.perl5.porters | Postings from May 2013

[perl #117539] Fix incorrect assumptions about gids & uids

Thread Previous | Thread Next
From:
Brian Fraser via RT
Date:
May 23, 2013 04:08
Subject:
[perl #117539] Fix incorrect assumptions about gids & uids
Message ID:
rt-3.6.HEAD-2650-1369282087-1548.117539-15-0@perl.org
On Wed Apr 10 17:57:48 2013, tonyc wrote:
> On Mon Apr 08 16:36:35 2013, Hugmeir wrote:
> > [Please describe your issue here]
> > 
> > See the attached patch. Copypasting the commit message here:
> > 
> >     Stop making assumptions about uids and gids.
> > 
> >     The code dealt rather inconsistently with uids and gids. Some
> >     places assumed that they could be safely stored in UVs, others
> >     in IVs, others in ints; All of them should've been using the
> >     macros from config.h instead. Similarly, code that created
> >     SVs or pushed values into the stack was also making incorrect
> >     assumptions -- For point of reference, only pp_stat did the
> >     right thing:
> > 
> >      #if Uid_t_size > IVSIZE
> >         mPUSHn(PL_statcache.st_uid);
> >      #else
> >      #   if Uid_t_sign <= 0
> >         mPUSHi(PL_statcache.st_uid);
> >      #   else
> >         mPUSHu(PL_statcache.st_uid);
> >      #   endif
> >      #endif
> 
> I'd be inclined to put that knowledge in a central place rather than
> #ifdeffing in every place, so for uids, two macros:
> 
>   sv_setuid
>   SvUID
> 
> The mPUSHi() etc would become
> 
>   sv_setuid(PUSHmortal, someuid);
> 
> (which might become a third macro, mPUSHuid)
> 
> These macros would only be visible in the core.
> 
> That said, I think this is an improvement.
> 
> Tony

Attached patch adds the suggested macros (SvUID, SvGID, sv_setuid, sv_setgid), and not only 
reworks the bits the original patch changed, but also simplifies & fixes other parts of the core 
that were checking [GU]id_t_size, sometimes erroneously.
Turns out that now the patch ends up removing more lines than it adds, which is always nice.

Adding mPUSHuid & mPUSHgid seemed like overkill for how few times they end up being used, 
so I didn't do that.

TonyC++, great feedback!
 
--hugmeir

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=117539

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