On Thu, Jul 23, 2009 at 11:48:19PM +0100, Stuart Henderson wrote:
> the buffer cherokee passes to getgrnam_r isn't large enough,
> 
> getgrent.c:
> 
> #define GETGR_R_SIZE_MAX        (1024+200*sizeof(char*))
> ...
>         if (bufsize < GETGR_R_SIZE_MAX)
>                 return ERANGE;
> 
> both places in cherokee that call cherokee_getgrnam (cherokee/server.c
> and cherokee/source_interpreter.c) use a 1KB buffer so they trigger
> the problem
> 
>                 struct group grp;
>                 char         tmp[1024];
> 
>                 ret = cherokee_getgrnam (conf->val.buf, &grp, tmp, 
> sizeof(tmp));
> 
> Apache 2 which also uses getgrnam_r() uses a different method and
> just uses a static 8K buffer.
> 
> #define GRBUF_SIZE 8192
> ...
>     char grbuf[GRBUF_SIZE];
> 
> from what I can tell it would be most correct, but perhaps not totally
> portable, to use sysconf(_SC_GETGR_R_SIZE_MAX) and dynamically allocate
> the buffer.
> 
> thoughts??

The portable way would be to enlarge the buffer and retry whenever
you get ERANGE. I ran into this problem several weeks ago for GHC
(and a diff doing the try/enlarge/retry-game had been accepted
upstream). IIRC, there even was some #ifdef'ing around that already
increased the buffer especially for OpenBSD, but that increase
wasn't large enough an 64bit archs (it did fit on 32bit archs).

Of course, the sysconf approach may work, too, but I don't know how
portable it is. IIRC, you *always* have to react on ERANGE and retry
to be portable.

Ciao,
        Kili

Reply via email to