From 8a9dc061f5737543eaca17ceafa6ebe4886cb26e Mon Sep 17 00:00:00 2001 From: kosaki Date: Thu, 21 Feb 2013 04:52:38 +0000 Subject: [PATCH] * file.c (rb_group_member): added an error check. SUS says, getgroups(small_value) may return EINVAL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ file.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index abe7005a63..69534f618a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 21 13:47:59 2013 KOSAKI Motohiro + + * file.c (rb_group_member): added an error check. SUS says, + getgroups(small_value) may return EINVAL. + Thu Feb 21 13:37:07 2013 KOSAKI Motohiro * file.c (RB_MAX_GROUPS): moved to diff --git a/file.c b/file.c index 1cc7f63d18..69b5a7cf4b 100644 --- a/file.c +++ b/file.c @@ -1036,7 +1036,7 @@ rb_group_member(GETGROUPS_T gid) while (groups <= RB_MAX_GROUPS) { gary = ALLOCV_N(GETGROUPS_T, v, groups); anum = getgroups(groups, gary); - if (anum != groups) + if (anum != -1 && anum != groups) break; groups *= 2; if (v) { @@ -1044,6 +1044,8 @@ rb_group_member(GETGROUPS_T gid) v = 0; } } + if (anum == -1) + return FALSE; while (--anum >= 0) { if (gary[anum] == gid) {