summaryrefslogtreecommitdiff
path: root/lib/getugroups.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-07-28 19:41:08 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-07-28 19:41:08 +0000
commit7c6ecf213aeb1d02b48742869229fffd358163d9 (patch)
tree0761990dfe6efcabac60b45cf991b13656e1d2e7 /lib/getugroups.c
parenta0cc71ff25bf3080adfda321b3ba327384f62d50 (diff)
downloadcoreutils-7c6ecf213aeb1d02b48742869229fffd358163d9.tar.xz
Include <errno.h>.
(EOVERFLOW): Define if not defined. (getgroups): Return -1 with errno=EOVERFLOW if an integer overflow occurs.
Diffstat (limited to 'lib/getugroups.c')
-rw-r--r--lib/getugroups.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/getugroups.c b/lib/getugroups.c
index b5e268777..dbd86ef93 100644
--- a/lib/getugroups.c
+++ b/lib/getugroups.c
@@ -1,5 +1,7 @@
/* getugroups.c -- return a list of the groups a user is in
- Copyright (C) 1990, 1991, 1998, 1999, 2000, 2003 Free Software Foundation.
+
+ Copyright (C) 1990, 1991, 1998, 1999, 2000, 2003, 2004 Free
+ Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,6 +31,11 @@
# include <unistd.h>
#endif
+#include <errno.h>
+#ifndef EOVERFLOW
+# define EOVERFLOW EINVAL
+#endif
+
/* setgrent, getgrent, and endgrent are not specified by POSIX.1,
so header files might not declare them.
If you don't have them at all, we can't implement this function.
@@ -88,6 +95,11 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char *username, gid_t gid)
grouplist[count] = grp->gr_gid;
}
count++;
+ if (count < 0)
+ {
+ errno = EOVERFLOW;
+ return -1;
+ }
}
}
}