$OpenBSD: patch-preserve_c,v 1.2 2003/01/21 05:16:43 danh Exp $ --- preserve.c.orig Wed Oct 24 02:22:42 2001 +++ preserve.c Mon Jan 20 23:51:14 2003 @@ -196,38 +196,38 @@ int save_state() /* Saving current run data... */ if (verbose>1) { - sprintf(buffer,"%02d/%02d/%04d %02d:%02d:%02d", + snprintf(buffer,sizeof buffer,"%02d/%02d/%04d %02d:%02d:%02d", cur_month,cur_day,cur_year,cur_hour,cur_min,cur_sec); printf("%s [%s]\n",msg_put_data,buffer); } /* first, save the easy stuff */ /* Header record */ - sprintf(buffer, + snprintf(buffer,sizeof buffer, "# Webalizer V%s-%s Incremental Data - %02d/%02d/%04d %02d:%02d:%02d\n", version,editlvl,cur_month,cur_day,cur_year,cur_hour,cur_min,cur_sec); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ /* Current date/time */ - sprintf(buffer,"%d %d %d %d %d %d\n", + snprintf(buffer,sizeof buffer,"%d %d %d %d %d %d\n", cur_year, cur_month, cur_day, cur_hour, cur_min, cur_sec); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ /* Monthly totals for sites, urls, etc... */ - sprintf(buffer,"%lu %lu %lu %lu %lu %lu %.0f %lu %lu %lu\n", + snprintf(buffer,sizeof buffer,"%lu %lu %lu %lu %lu %lu %.0f %lu %lu %lu\n", t_hit, t_file, t_site, t_url, t_ref, t_agent, t_xfer, t_page, t_visit, t_user); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ /* Daily totals for sites, urls, etc... */ - sprintf(buffer,"%lu %lu %lu %d %d\n", + snprintf(buffer,sizeof buffer,"%lu %lu %lu %d %d\n", dt_site, ht_hit, mh_hit, f_day, l_day); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ /* Monthly (by day) total array */ for (i=0;i<31;i++) { - sprintf(buffer,"%lu %lu %.0f %lu %lu %lu\n", + snprintf(buffer,sizeof buffer,"%lu %lu %.0f %lu %lu %lu\n", tm_hit[i],tm_file[i],tm_xfer[i],tm_site[i],tm_page[i],tm_visit[i]); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ } @@ -235,7 +235,7 @@ int save_state() /* Daily (by hour) total array */ for (i=0;i<24;i++) { - sprintf(buffer,"%lu %lu %.0f %lu\n", + snprintf(buffer,sizeof buffer,"%lu %lu %.0f %lu\n", th_hit[i],th_file[i],th_xfer[i],th_page[i]); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ } @@ -243,7 +243,7 @@ int save_state() /* Response codes */ for (i=0;istring, + snprintf(buffer,sizeof buffer,"%s\n%d %lu %lu %.0f %lu %lu\n", uptr->string, uptr->flag, uptr->count, uptr->files, uptr->xfer, uptr->entry, uptr->exit); if (fputs(buffer,fp)==EOF) return 1; @@ -272,7 +272,7 @@ int save_state() hptr=sm_htab[i]; while (hptr!=NULL) { - sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n%s\n", + snprintf(buffer,sizeof buffer,"%s\n%d %lu %lu %.0f %lu %lu\n%s\n", hptr->string, hptr->flag, hptr->count, @@ -294,7 +294,7 @@ int save_state() hptr=sd_htab[i]; while (hptr!=NULL) { - sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n%s\n", + snprintf(buffer,sizeof buffer,"%s\n%d %lu %lu %.0f %lu %lu\n%s\n", hptr->string, hptr->flag, hptr->count, @@ -318,7 +318,7 @@ int save_state() rptr=rm_htab[i]; while (rptr!=NULL) { - sprintf(buffer,"%s\n%d %lu\n", rptr->string, + snprintf(buffer,sizeof buffer,"%s\n%d %lu\n", rptr->string, rptr->flag, rptr->count); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ rptr=rptr->next; @@ -336,7 +336,7 @@ int save_state() aptr=am_htab[i]; while (aptr!=NULL) { - sprintf(buffer,"%s\n%d %lu\n", aptr->string, + snprintf(buffer,sizeof buffer,"%s\n%d %lu\n", aptr->string, aptr->flag, aptr->count); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ aptr=aptr->next; @@ -352,7 +352,7 @@ int save_state() sptr=sr_htab[i]; while (sptr!=NULL) { - sprintf(buffer,"%s\n%lu\n", sptr->string,sptr->count); + snprintf(buffer,sizeof buffer,"%s\n%lu\n", sptr->string,sptr->count); if (fputs(buffer,fp)==EOF) return 1; /* error exit */ sptr=sptr->next; } @@ -367,7 +367,7 @@ int save_state() iptr=im_htab[i]; while (iptr!=NULL) { - sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n", + snprintf(buffer,sizeof buffer,"%s\n%d %lu %lu %.0f %lu %lu\n", iptr->string, iptr->flag, iptr->count, @@ -417,7 +417,7 @@ int restore_state() if (verbose>1) printf("%s %s\n",msg_get_data,state_fname); /* get easy stuff */ - sprintf(tmp_buf,"# Webalizer V%s ",version); + snprintf(tmp_buf,sizeof tmp_buf,"# Webalizer V%s ",version); if ((fgets(buffer,BUFSIZE,fp)) != NULL) /* Header record */ {if (strncmp(buffer,tmp_buf,17)) return 99;} /* bad magic? */ else return 1; /* error exit */ @@ -493,7 +493,7 @@ int restore_state() while ((fgets(buffer,BUFSIZE,fp)) != NULL) { if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXURLH); + strlcpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(tmp_buf)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 10; /* error exit */ @@ -524,7 +524,7 @@ int restore_state() { /* Check for end of table */ if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXHOST); + strlcpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(buffer)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 8; /* error exit */ @@ -564,7 +564,7 @@ int restore_state() { /* Check for end of table */ if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXHOST); + strlcpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(buffer)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 9; /* error exit */ @@ -603,7 +603,7 @@ int restore_state() while ((fgets(buffer,BUFSIZE,fp)) != NULL) { if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXREFH); + strlcpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(buffer)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 11; /* error exit */ @@ -628,7 +628,7 @@ int restore_state() while ((fgets(buffer,BUFSIZE,fp)) != NULL) { if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXAGENT); + strlcpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(buffer)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 12; /* error exit */ @@ -653,7 +653,7 @@ int restore_state() while ((fgets(buffer,BUFSIZE,fp)) != NULL) { if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXSRCH); + strlcpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(buffer)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 13; /* error exit */ @@ -678,7 +678,7 @@ int restore_state() { /* Check for end of table */ if (!strncmp(buffer,"# End Of Table ",15)) break; - strncpy(tmp_buf,buffer,MAXIDENT); + strncpy(tmp_buf,buffer,sizeof tmp_buf); tmp_buf[strlen(buffer)-1]=0; if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 14; /* error exit */