aboutsummaryrefslogtreecommitdiffstats
path: root/uidlist.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2004-02-20 17:09:30 +0000
committerWayne Davison <wayned@samba.org>2004-02-20 17:09:30 +0000
commitf567e9b3d7e4e2c5a4dfa35a2ecbb973aa46ce73 (patch)
treea99eb85ab8c65b8a6f9aa070f5ca46ab6b655da2 /uidlist.c
parent40ae4f93a079ed71e491e6d51914d6d663ea3f10 (diff)
downloadandroid_external_rsync-f567e9b3d7e4e2c5a4dfa35a2ecbb973aa46ce73.tar.gz
android_external_rsync-f567e9b3d7e4e2c5a4dfa35a2ecbb973aa46ce73.tar.bz2
android_external_rsync-f567e9b3d7e4e2c5a4dfa35a2ecbb973aa46ce73.zip
- Guard against and out-of-memory condition.
- Don't use the NGROUPS_MAX define.
Diffstat (limited to 'uidlist.c')
-rw-r--r--uidlist.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/uidlist.c b/uidlist.c
index 246e6fa5..dbffb05f 100644
--- a/uidlist.c
+++ b/uidlist.c
@@ -29,10 +29,6 @@
# if !defined(GETGROUPS_T)
# define GETGROUPS_T gid_t
# endif
-# ifndef NGROUPS_MAX
-/* It ought to be defined, but just in case. */
-# define NGROUPS_MAX 32
-# endif
#endif
extern int verbose;
@@ -110,9 +106,11 @@ static int is_in_group(gid_t gid)
return last_out;
if (ngroups < -1) {
gid_t mygid = MY_GID();
- if ((ngroups = getgroups(0, 0)) < 0)
+ if ((ngroups = getgroups(0, NULL)) < 0)
ngroups = 0;
gidset = new_array(GETGROUPS_T, ngroups+1);
+ if (!gidset)
+ out_of_memory("is_in_group");
if (ngroups > 0)
ngroups = getgroups(ngroups, gidset);
/* The default gid might not be in the list on some systems. */
@@ -123,8 +121,10 @@ static int is_in_group(gid_t gid)
if (n == ngroups)
gidset[ngroups++] = mygid;
if (verbose > 3) {
- char gidbuf[NGROUPS_MAX*16+32];
int pos;
+ char *gidbuf = new_array(char, ngroups*21+32);
+ if (!gidbuf)
+ out_of_memory("is_in_group");
sprintf(gidbuf, "process has %d gid%s: ",
ngroups, ngroups == 1? "" : "s");
pos = strlen(gidbuf);
@@ -133,6 +133,7 @@ static int is_in_group(gid_t gid)
pos += strlen(gidbuf+pos);
}
rprintf(FINFO, "%s\n", gidbuf);
+ free(gidbuf);
}
}