|
From: <sv...@va...> - 2014-09-30 18:14:10
|
Author: florian
Date: Tue Sep 30 19:14:03 2014
New Revision: 14593
Log:
Make the semantics if VG_(getgroups) match those of getgroups(2).
That is, add the special case (size == 0) to query the number of
supplementary group IDs. This simplifies the call site nicely.
Modified:
branches/BUF_REMOVAL/coregrind/m_libcfile.c
branches/BUF_REMOVAL/coregrind/m_libcproc.c
Modified: branches/BUF_REMOVAL/coregrind/m_libcfile.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_libcfile.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_libcfile.c Tue Sep 30 19:14:03 2014
@@ -658,15 +658,16 @@
grpmatch = 1;
else {
UInt *groups = NULL;
- Int ngrp, groups_size = 0;
- do {
- groups_size += 32;
- groups = VG_(arena_realloc)(VG_AR_CORE, "check_executable",
- groups, groups_size);
- ngrp = VG_(getgroups)(groups_size, groups);
- if (ngrp == -1) break; // failed
- } while (ngrp == groups_size);
- Int i;
+ 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) {
@@ -674,7 +675,7 @@
break;
}
}
- if (groups) VG_(free)(groups);
+ VG_(free)(groups);
}
if (grpmatch) {
Modified: branches/BUF_REMOVAL/coregrind/m_libcproc.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_libcproc.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_libcproc.c Tue Sep 30 19:14:03 2014
@@ -532,7 +532,9 @@
/* 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;
@@ -545,8 +547,10 @@
sres = VG_(do_syscall2)(__NR_getgroups, size, (Addr)list16);
if (sr_isError(sres))
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) \
|