Expand buffer for group information if too small and retry

This commit is contained in:
Tony Levi 2017-05-23 00:46:41 +09:30
parent ae4caa96a0
commit 2b7ea5813c

View File

@ -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;
}