diff options
-rw-r--r-- | source/nsswitch/winbind_nss_linux.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/source/nsswitch/winbind_nss_linux.c b/source/nsswitch/winbind_nss_linux.c index ae2bcc7ade9..a6d0bfe4e86 100644 --- a/source/nsswitch/winbind_nss_linux.c +++ b/source/nsswitch/winbind_nss_linux.c @@ -833,25 +833,38 @@ _nss_winbind_initgroups_dyn(char *user, gid_t group, long int *start, /* Skip primary group */ - if (gid_list[i] == group) continue; - - /* Add to buffer */ + if (gid_list[i] == group) { + continue; + } - if (*start == *size && limit <= 0) { - (*groups) = realloc( - (*groups), (2 * (*size) + 1) * sizeof(**groups)); - if (! *groups) goto done; - *size = 2 * (*size) + 1; + /* Filled buffer ? If so, resize. */ + + if (*start == *size) { + long int newsize; + gid_t *newgroups; + + newsize = 2 * (*size); + if (limit > 0) { + if (*size == limit) { + goto done; + } + newsize = MIN(newsize, limit); + } + + newgroups = realloc((*groups), newsize * sizeof(**groups)); + if (!newgroups) { + *errnop = ENOMEM; + ret = NSS_STATUS_NOTFOUND; + goto done; + } + *groups = newgroups; + *size = newsize; } - if (*start == *size) goto done; + /* Add to buffer */ (*groups)[*start] = gid_list[i]; *start += 1; - - /* Filled buffer? */ - - if (*start == limit) goto done; } } |