From: Florian Krohm Date: Tue, 30 Sep 2014 19:26:58 +0000 (+0000) Subject: Merge revisions 14216,14591,14593 from the BUF_REMOVAL branch to trunk. X-Git-Tag: svn/VALGRIND_3_11_0~947 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b641262cb8b1e4e7d6c4b766b7c1c24200257315;p=thirdparty%2Fvalgrind.git Merge revisions 14216,14591,14593 from the BUF_REMOVAL branch to trunk. Chang the semantics of VG_(getgroups) to support querying the number of supplementary group IDs which simplifies obtaining them and gets rid of fixed size buffers. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14594 --- diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index ceb6bdc1ef..06a4461676 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -615,9 +615,17 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid, if (VG_(getegid)() == st.gid) grpmatch = 1; else { - UInt groups[32]; - Int ngrp = VG_(getgroups)(32, groups); - Int i; + UInt *groups = NULL; + Int ngrp; + + /* Find out # groups, allocate large enough array and fetch groups */ + ngrp = VG_(getgroups)(0, NULL); + if (ngrp != -1) { + groups = VG_(malloc)("check_executable", ngrp * sizeof *groups); + ngrp = VG_(getgroups)(ngrp, groups); + } + + Int i; /* ngrp will be -1 if VG_(getgroups) failed. */ for (i = 0; i < ngrp; i++) { if (groups[i] == st.gid) { @@ -625,6 +633,7 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid, break; } } + VG_(free)(groups); } if (grpmatch) { diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c index 98c625f1de..cc285c437a 100644 --- a/coregrind/m_libcproc.c +++ b/coregrind/m_libcproc.c @@ -532,23 +532,25 @@ Int VG_(getegid) ( void ) /* Get supplementary groups into list[0 .. size-1]. Returns the number of groups written, or -1 if error. Note that in order to be portable, the groups are 32-bit unsigned ints regardless of the - platform. */ + platform. + As a special case, if size == 0 the function returns the number of + groups leaving list untouched. */ Int VG_(getgroups)( Int size, UInt* list ) { + if (size < 0) return -1; + # if defined(VGP_x86_linux) || defined(VGP_ppc32_linux) \ || defined(VGP_mips64_linux) Int i; SysRes sres; - UShort list16[64]; - if (size < 0) return -1; - if (size > 64) size = 64; + UShort list16[size]; sres = VG_(do_syscall2)(__NR_getgroups, size, (Addr)list16); if (sr_isError(sres)) return -1; - if (sr_Res(sres) > size) - return -1; - for (i = 0; i < sr_Res(sres); i++) - list[i] = (UInt)list16[i]; + if (size != 0) { + for (i = 0; i < sr_Res(sres); i++) + list[i] = (UInt)list16[i]; + } return sr_Res(sres); # elif defined(VGP_amd64_linux) || defined(VGP_arm_linux) \