Package: webalizer
Severity: wishlist
Tags: patch upstream

I've had very serious issues with webalizer truncating history and state
files to 0.  There is currently a time frame between fopen and the actual
state writing during which a segfault or the likes would result in severe
corruption.

I've made this patch to create a temporary "*.new" file and only replace
the old ones when we're finished generating them.

Already sent to upstream.

-- 
Robert Millan

ACK STORM, S.L.  -  http://www.ackstorm.es/
diff -ur webalizer-2.01.10.old/preserve.c webalizer-2.01.10/preserve.c
--- webalizer-2.01.10.old/preserve.c	2001-10-24 08:22:42.000000000 +0200
+++ webalizer-2.01.10/preserve.c	2007-02-20 13:59:19.000000000 +0100
@@ -141,8 +141,10 @@
 {
    int i;
    FILE *hist_fp;
+   char *tmp;
 
-   hist_fp = fopen(hist_fname,"w");
+   asprintf (&tmp, "%s.new", hist_fname);
+   hist_fp = fopen(tmp,"w");
 
    if (hist_fp)
    {
@@ -165,10 +167,14 @@
          }
       }
       fclose(hist_fp);
+      if ((rename (tmp,hist_fname) == -1) && verbose)
+        fprintf(stderr,"Failed renaming %s to %s\n",tmp,hist_fname);
    }
    else
       if (verbose)
       fprintf(stderr,"%s %s\n",msg_hist_err,hist_fname);
+
+  free(tmp);
 }
 
 /*********************************************/
@@ -186,11 +192,14 @@
 
    FILE *fp;
    int  i;
+   char *tmp;
 
    char buffer[BUFSIZE];
 
    /* Open data file for write */
-   fp=fopen(state_fname,"w");
+   asprintf(&tmp, "%s.new", state_fname);
+   fp=fopen(tmp,"w");
+   free(tmp);
    if (fp==NULL) return 1;
 
    /* Saving current run data... */
@@ -382,6 +391,16 @@
    if (fputs("# End Of Table - usernames\n",fp)==EOF) return 1;
 
    fclose(fp);          /* close data file...                            */
+
+   asprintf(&tmp, "%s.new", state_fname);
+   if ((rename (tmp,state_fname) == -1) && verbose)
+     {
+       fprintf(stderr,"Failed renaming %s to %s\n",tmp,state_fname);
+       free(tmp);
+       return 1;
+     }
+   free(tmp);
+
    return 0;            /* successful, return with good return code      */
 }
 

Reply via email to