From 2b7ea5813c39ea51b6f32c2f8997b2c95da64eb9 Mon Sep 17 00:00:00 2001 From: Tony Levi Date: Tue, 23 May 2017 00:46:41 +0930 Subject: [PATCH] Expand buffer for group information if too small and retry --- src/s3fs_util.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index 7759c2e..9dafb6c 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -510,8 +510,17 @@ int is_uid_include_group(uid_t uid, gid_t gid) return -ENOMEM; } // get group information - if(0 != (result = getgrgid_r(gid, &ginfo, pbuf, maxlen, &pginfo))){ - S3FS_PRN_ERR("could not get group information."); + while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf, maxlen, &pginfo))){ + free(pbuf); + maxlen *= 2; + if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){ + S3FS_PRN_CRIT("failed to allocate memory."); + return -ENOMEM; + } + } + + if(0 != result){ + S3FS_PRN_ERR("could not get group information(%d).", result); free(pbuf); return -result; }