summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/cfsysline.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c
index 4997e0fb..a33810ed 100644
--- a/runtime/cfsysline.c
+++ b/runtime/cfsysline.c
@@ -338,11 +338,12 @@ static int doParseOnOffOption(uchar **pp)
*/
static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
{
- struct group *pgBuf;
+ struct group *pgBuf = NULL;
struct group gBuf;
DEFiRet;
uchar szName[256];
- char stringBuf[2048]; /* I hope this is large enough... */
+ long bufSize = 2048;
+ char * stringBuf = malloc(bufSize);
assert(pp != NULL);
assert(*pp != NULL);
@@ -352,7 +353,15 @@ static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p
ABORT_FINALIZE(RS_RET_NOT_FOUND);
}
- getgrnam_r((char*)szName, &gBuf, stringBuf, sizeof(stringBuf), &pgBuf);
+ while(pgBuf == NULL) {
+ errno = 0;
+ getgrnam_r((char*)szName, &gBuf, stringBuf, bufSize, &pgBuf);
+ if((pgBuf == NULL) && (errno == ERANGE)) {
+ /* Increase bufsize and try again.*/
+ bufSize *= 2;
+ stringBuf = realloc(stringBuf, bufSize);
+ }
+ }
if(pgBuf == NULL) {
errmsg.LogError(0, RS_RET_NOT_FOUND, "ID for group '%s' could not be found or error", (char*)szName);