[sheepdog] [PATCH] sheep: add a helper function to copy out data from strbuf

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sun May 20 18:43:28 CEST 2012


At Sun, 20 May 2012 12:25:03 -0400,
Christoph Hellwig wrote:
> 
> On Mon, May 21, 2012 at 12:23:53AM +0900, MORITA Kazutaka wrote:
> > This patch also fixes a problem that local_get_store_list() doesn't
> > set a null terminated string.
> 
> I took a quick look at the strbuf code but can't see any explanation
> how the extra byte that it apparenly makes sure is always allocated is
> set to 0.  Any chance we could get a bit of documentation for this code?

strbuf_setlen() seems to add the trailing null character.  Yuan, can
you add comments to strbuf code?

> 
> Also how do we know the buffer we copy the strbuf to is guaranteed to be
> large enough?

I just wrapped memcpy with strbuf_copyout, and the original code has
the problem of buffer overflow.  But I should have added the third
argument to strbuf_copyout() to notify the size of the destination
buffer.

Thanks,

Kazutaka



More information about the sheepdog mailing list