On Thu, Jan 15, 2009 at 04:54:23PM -0700, Brad Nicholes wrote:
> Since it is limited by REQUESTLEN, I am OK with it. So it sounds like
> we just need a fix for the off-by-one and the check for NULL on the
> malloc.
What about this patch then?
Kostas
diff --git a/monitor-core/gmetad/server.c b/monitor-core/gmetad/server.c
index eb21449..52b22b3 100644
--- a/monitor-core/gmetad/server.c
+++ b/monitor-core/gmetad/server.c
@@ -371,8 +371,7 @@ tree_report(datum_t *key, datum_t *val, void *arg)
/* sacerdoti: This function does a tree walk while respecting the filter path.
* Will return valid XML even if we have chosen a subtree. Since tree depth is
- * bounded, this function guarantees O(1) search time. The recursive structure
- * does not require any memory allocations.
+ * bounded, this function guarantees O(1) search time.
*/
static int
process_path (client_t *client, char *path, datum_t *myroot, datum_t *key)
@@ -421,7 +420,9 @@ process_path (client_t *client, char *path, datum_t
*myroot, datum_t *key)
len = q-p;
/* +1 not needed as q-p is already accounting for that */
- element = malloc(len);
+ element = malloc(len + 1);
+ if ( element == NULL )
+ return 1;
strncpy(element, p, len);
element[len] = '\0';
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Ganglia-developers mailing list
Ganglia-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ganglia-developers