On Thu, Feb 24, 2011 at 02:06:44AM +0000, Kostas Georgiou wrote:
> 
> In any case the slurpfile resizable buffer doesn't really work :(

obviously there is a misunderstanding about what this code does, and
it is not "resizable buffer", but avoiding buffer overflows when passed
more data than it can handle (which before resulted in buffer overflows
and crashes))

> slurpfile only resizes a buffer if it's NULL but this is the case
> only at the first call for a metric.

and is only used this way when processing /proc/stat where we only really
cared about the first line of that file, most of the time.

this means that you only care on allocating a buffer that is big enough
for the first time the file is read, and considering that it is allocated
in page multiples of 4K each it is likely to be fine even if the file
grows slightly the next time.

> char *bp=NULL;
> slurpfile(file, &bp, 32);  
> ...next polling interval...
> /* the buffer isn't resibale any more since it isn't NULL */
> slurpfile(file, &bp, 32);  

slurpfile wasn't designed to be used this way, specially considering that
it will waste more bytes just creating a pointer if you really only wanted
to have 32 bytes to begin with.

but if you really want to push the code to work in this scenario, no one
is preventing you to clean the buffer before calling slurpfile :

  free(bp);
  bp = NULL;

don't forget though that my objective here was to change the code to avoid
the posibility of buffer overflows (which is why the message says that) and
the message is there to clarify why something was truncated (while before
it would just instead corrupt itself and crash).

in summary, slurpfile is a hack, and should be avoided if possible, but was
kept in its most benign form until its users can be implemented in a better
way.

Carlo

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Ganglia-developers mailing list
Ganglia-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to