X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Frrd_restore.c;h=b283f9128594f21f27bb83c70112cb7776d88abb;hb=0682078d272dd11eb63c5ee8e5a095f578d540e9;hp=51def7e465e2c16736c66310ae271c4f78d7aa63;hpb=a9e69acbc184063dcc0eda6a250ee1b7ae1cbb47;p=rrdtool.git diff --git a/src/rrd_restore.c b/src/rrd_restore.c index 51def7e..b283f91 100644 --- a/src/rrd_restore.c +++ b/src/rrd_restore.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.13 Copyright by Tobi Oetiker, 1997-2006 + * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 ***************************************************************************** * rrd_restore.c creates new rrd from data dumped by rrd_dump.c *****************************************************************************/ @@ -18,10 +18,11 @@ void xml_lc(char*); int skip(char **); +int skipxml(char **); int eat_tag(char **, char *); int read_tag(char **, char *, char *, void *); int xml2rrd(char*, rrd_t*, char); -int rrd_write(char *, rrd_t *, char); +int rrd_creat(char *, rrd_t *, char); void parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index); void parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index); void parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index); @@ -44,12 +45,32 @@ void xml_lc(char* buf){ } } -int skip(char **buf){ +int skipxml(char **buf){ char *ptr; ptr=(*buf); do { (*buf)=ptr; while((*(ptr+1)) && ((*ptr)==' ' || (*ptr)=='\r' || (*ptr)=='\n' || (*ptr)=='\t')) ptr++; + if (strncmp(ptr,""); + if (ptr) ptr+=2; else { + rrd_set_error("Dangling XML header"); + (*buf) = NULL; + return -1; + } + } + } while ((*buf)!=ptr); + return 1; +} + +int skip(char **buf){ + char *ptr; + if ((buf == NULL) || (*buf == NULL)) + return -1; + ptr=(*buf); + do { + (*buf)=ptr; + while((*(ptr+1)) && ((*ptr)==' ' || (*ptr)=='\r' || (*ptr)=='\n' || (*ptr)=='\t')) ptr++; if (strncmp(ptr,""); if (ptr) ptr+=3; else { @@ -118,6 +139,8 @@ int xml2rrd(char* buf, rrd_t* rrd, char rc){ ptr2=buf; ptr3=buf; /* start with an RRD tag */ + + skipxml(&ptr); eat_tag(&ptr,"rrd"); /* allocate static header */ @@ -191,8 +214,9 @@ int xml2rrd(char* buf, rrd_t* rrd, char rc){ read_tag(&ptr2,"max","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_max_val].u_val)); } else { /* DST_CDEF */ char buffer[1024]; - read_tag(&ptr2,"cdef","%s",buffer); + read_tag(&ptr2,"cdef","%1000s",buffer); parseCDEF_DS(buffer,rrd,rrd -> stat_head -> ds_cnt - 1); + if (rrd_test_error()) return -1; } read_tag(&ptr2,"last_ds","%30s",rrd->pdp_prep[rrd->stat_head->ds_cnt-1].last_ds); @@ -215,7 +239,7 @@ int xml2rrd(char* buf, rrd_t* rrd, char rc){ if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep, rrd->stat_head->rra_cnt *rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){ - rrd_set_error("allocating cdp_prep"); return -1; } + rrd_set_error("allocating cdp_prep"); return -1; } memset(&(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rrd->stat_head->rra_cnt-1)]), 0, rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)); @@ -232,7 +256,10 @@ int xml2rrd(char* buf, rrd_t* rrd, char rc){ read_tag(&ptr2, "xff","%lf", &(rrd->rra_def[rra_index].par[RRA_cdp_xff_val].u_val)); } else { - eat_tag(&ptr2, "params"); + if (eat_tag(&ptr2, "params") != 1) { + rrd_set_error("could not find params tag to eat and skip"); + return -1; + } skip(&ptr2); /* backwards compatibility w/ old patch */ if (strncmp(ptr2, "",7) == 0) { @@ -434,7 +461,7 @@ int xml2rrd(char* buf, rrd_t* rrd, char rc){ /* create and empty rrd file according to the specs given */ int -rrd_write(char *file_name, rrd_t *rrd, char force_overwrite) +rrd_creat(char *file_name, rrd_t *rrd, char force_overwrite) { unsigned long i,ii,val_cnt; FILE *rrd_file=NULL; @@ -557,7 +584,7 @@ rrd_restore(int argc, char **argv) free(buf); - if(rrd_write(argv[optind+1],&rrd,force_overwrite)==-1){ + if(rrd_creat(argv[optind+1],&rrd,force_overwrite)==-1){ rrd_free(&rrd); return -1; };