From: Steve Peters Date: Mon, 26 Dec 2005 17:29:13 +0000 (+0000) Subject: In this, the last tale of the NGROUPS saga, a former pumpking prods X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=757f63d8f908c08ca232cfc2d4d7d79164eb223e;p=p5sagit%2Fp5-mst-13.2.git In this, the last tale of the NGROUPS saga, a former pumpking prods a mere committer to remove the last of the NGROUPS-sized arrays... Perl_magic_set() was using the last of these arrays to do the lvalue work on $). Instead of an array, a pointer is used and re-sized as needed. p4raw-id: //depot/perl@26492 --- diff --git a/mg.c b/mg.c index 5072a8f..8172c4c 100644 --- a/mg.c +++ b/mg.c @@ -40,14 +40,17 @@ tie. #include "perl.h" #if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS) -# ifndef NGROUPS -# define NGROUPS 32 -# endif # ifdef I_GRP # include # endif #endif +#if defined(HAS_SETGROUPS) +# ifndef NGROUPS +# define NGROUPS 32 +# endif +#endif + #ifdef __hpux # include #endif @@ -2489,22 +2492,28 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) #ifdef HAS_SETGROUPS { const char *p = SvPV_const(sv, len); - Groups_t gary[NGROUPS]; - - while (isSPACE(*p)) - ++p; - PL_egid = Atol(p); - for (i = 0; i < NGROUPS; ++i) { - while (*p && !isSPACE(*p)) - ++p; - while (isSPACE(*p)) - ++p; - if (!*p) - break; - gary[i] = Atol(p); - } - if (i) - (void)setgroups(i, gary); + Groups_t *gary = NULL; + + while (isSPACE(*p)) + ++p; + PL_egid = Atol(p); + for (i = 0; i < NGROUPS; ++i) { + while (*p && !isSPACE(*p)) + ++p; + while (isSPACE(*p)) + ++p; + if (!*p) + break; + if(!gary) + Newx(gary, i + 1, Groups_t); + else + Renew(gary, i + 1, Groups_t); + gary[i] = Atol(p); + } + if (i) + (void)setgroups(i, gary); + if (gary) + Safefree(gary); } #else /* HAS_SETGROUPS */ PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);