From e8bc0583fb8b9c3fd86cbd74da75032fcd6975ce Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 26 Dec 2010 17:13:08 +0000 Subject: [PATCH] add some extra checks to RRA arguments git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2158 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_create.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/program/src/rrd_create.c b/program/src/rrd_create.c index f221c99d..a36b31d1 100644 --- a/program/src/rrd_create.c +++ b/program/src/rrd_create.c @@ -275,9 +275,10 @@ int rrd_create_r2( } else if (strncmp(argv[i], "RRA:", 4) == 0) { char *argvcopy; char *tokptr = ""; + int cf_id = -1; size_t old_size = sizeof(rra_def_t) * (rrd.stat_head->rra_cnt); int row_cnt; - + int token_min = 4; if ((rrd.rra_def = (rra_def_t*)rrd_realloc(rrd.rra_def, old_size + sizeof(rra_def_t))) == NULL) { @@ -291,6 +292,7 @@ int rrd_create_r2( argvcopy = strdup(argv[i]); token = strtok_r(&argvcopy[4], ":", &tokptr); token_idx = error_flag = 0; + while (token != NULL) { switch (token_idx) { case 0: @@ -298,11 +300,12 @@ int rrd_create_r2( rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam) != 1) rrd_set_error("Failed to parse CF name"); - switch (cf_conv - (rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam)) { + cf_id = cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam); + switch (cf_id) { case CF_MHWPREDICT: strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */ case CF_HWPREDICT: + token_min = 5; /* initialize some parameters */ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha]. u_val = 0.1; @@ -313,7 +316,11 @@ int rrd_create_r2( rrd.stat_head->rra_cnt; break; case CF_DEVSEASONAL: + token_min = 3; case CF_SEASONAL: + if (cf_id == CF_SEASONAL){ + token_min = 4; + } /* initialize some parameters */ rrd.rra_def[rrd.stat_head->rra_cnt]. par[RRA_seasonal_gamma].u_val = 0.1; @@ -321,10 +328,14 @@ int rrd_create_r2( par[RRA_seasonal_smoothing_window].u_val = 0.05; /* fall through */ case CF_DEVPREDICT: + if (cf_id == CF_DEVPREDICT){ + token_min = 3; + } rrd.rra_def[rrd.stat_head->rra_cnt]. par[RRA_dependent_rra_idx].u_cnt = -1; break; case CF_FAILURES: + token_min = 5; rrd.rra_def[rrd.stat_head->rra_cnt]. par[RRA_delta_pos].u_val = 2.0; rrd.rra_def[rrd.stat_head->rra_cnt]. @@ -546,6 +557,11 @@ int rrd_create_r2( token_idx++; } /* end while */ free(argvcopy); + if (token_idx < token_min){ + rrd_set_error("Expected at least %i arguments for RRA but got %i",token_min,token_idx); + rrd_free2(&rrd); + return(-1); + } #ifdef DEBUG fprintf(stderr, "Creating RRA CF: %s, dep idx %lu, current idx %lu\n", -- 2.30.2