]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Report any error while reading the day summary file
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 1 Feb 2012 10:17:18 +0000 (11:17 +0100)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 1 Feb 2012 10:17:18 +0000 (11:17 +0100)
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

index eb6ee5e41ad8d4fa7b0dc16f487293c0eda1cde2..dd2bf4a1581c7759efff95b7cde98776af9bf47e 100644 (file)
--- 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 && daynum!=daylist[dayidx] ; dayidx++);
                if (dayidx>=ndaylist) {
@@ -116,13 +125,16 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo)
        for (i=0 ; i<sizeof(tbytes)/sizeof(*tbytes) ; i++) {
                if (tbytes[i]==0 && telap[i]==0) continue;
                dayidx=i/24;
-               if (dayidx>=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);