From 44bdeb6068ff8eb20c25e9601e90fd660febb852 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Wed, 1 Feb 2012 11:17:18 +0100 Subject: [PATCH] Report any error while reading the day summary file Sarg generates a temporary file containing the downloaded bytes and the elapsed time to produce the user's hourly report. While that temporary file is read and processed into yet another temporary file, any error found is reported and the processing is aborted instead of being silently ignored. It ensure no data are missing from the reports. --- totday.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/totday.c b/totday.c index eb6ee5e..dd2bf4a 100644 --- a/totday.c +++ b/totday.c @@ -33,7 +33,7 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo) char buf[200]; char date[20]; - long long int hour; + int hour; long long int bytes; long long int elap; long long int tbytes[MAX_DATETIME_DAYS*24]; @@ -73,13 +73,22 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo) while(fgets(buf,sizeof(buf),fp_in)!=NULL) { fixendofline(buf); getword_start(&gwarea,buf); - if (getword(date,sizeof(date),&gwarea,'\t')<0 || getword_atoll(&hour,&gwarea,'\t')<0) { + if (getword(date,sizeof(date),&gwarea,'\t')<0 || getword_atoi(&hour,&gwarea,'\t')<0) { debuga(_("There is a broken record or garbage in file %s\n"),wdirname); exit(EXIT_FAILURE); } - if (sscanf(date,"%d/%d/%d",&day,&month,&year)!=3) continue; - if (day<1 || day>31 || month<1 || month>12 || year>9999) continue; - if (hour<0 || hour>=24) continue; + if (sscanf(date,"%d/%d/%d",&day,&month,&year)!=3) { + debuga(_("Invalid date \"%s\" in %s\n"),date,wdirname); + exit(EXIT_FAILURE); + } + if (day<1 || day>31 || month<1 || month>12 || year>9999) { + debuga(_("Invalid date component in \"%s\" in %s\n"),date,wdirname); + exit(EXIT_FAILURE); + } + if (hour<0 || hour>=24) { + debuga(_("Invalid hour %d in %s\n"),hour,wdirname); + exit(EXIT_FAILURE); + } daynum=(year*10000)+(month*100)+day; for (dayidx=0 ; dayidx=ndaylist) { @@ -116,13 +125,16 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo) for (i=0 ; i=sizeof(daylist)/sizeof(*daylist)) continue; + if (dayidx>=sizeof(daylist)/sizeof(*daylist)) { + debuga(_("Invalid day index found in %s\n"),wdirname); + exit(EXIT_FAILURE); + } hour=i%24; daynum=daylist[dayidx]; day=daynum%100; month=(daynum/100)%100; year=daynum/10000; - fprintf(fp_ou,"%d/%d/%d\t%d",day,month,year,(int)hour); + fprintf(fp_ou,"%d/%d/%d\t%d",day,month,year,hour); if ((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRIu64"",(uint64_t)tbytes[i]); if ((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRIu64"",(uint64_t)telap[i]); fputs("\n",fp_ou); -- 2.47.2