From d2fe0c321366fb838479ec9f53198b008a383f1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Thu, 9 Jul 2009 13:05:23 +0000 Subject: [PATCH] Applied an extended version of debian patch: opensuse_5_limit_sprintf.patch Function debuga format the output string itself, so there is no need to use sprintf. --- configure | 3 +- configure.in | 2 +- dansguardian_log.c | 12 ++---- datafile.c | 7 +--- decomp.c | 20 ++++------ getconf.c | 6 +-- html.c | 11 ++---- include/conf.h | 3 ++ include/defs.h | 2 +- index.c | 2 +- lastlog.c | 6 +-- log.c | 91 +++++++++++++++++----------------------------- report.c | 3 +- sort.c | 6 +-- squidguard_log.c | 9 ++--- useragent.c | 11 ++---- util.c | 17 +++++---- 17 files changed, 83 insertions(+), 128 deletions(-) diff --git a/configure b/configure index 35ae8f1..7f845cf 100755 --- a/configure +++ b/configure @@ -4668,12 +4668,13 @@ done + for ac_header in stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \ dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \ ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \ - errno.h sys/resource.h sys/wait.h + errno.h sys/resource.h sys/wait.h stdarg.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then diff --git a/configure.in b/configure.in index 108ebff..156046a 100644 --- a/configure.in +++ b/configure.in @@ -48,7 +48,7 @@ fi AC_CHECK_HEADERS(stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \ dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \ ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \ - errno.h sys/resource.h sys/wait.h) + errno.h sys/resource.h sys/wait.h stdarg.h) AC_CHECK_LIB(gd, gdImagePng,LIBS="-lgd ${LIBS}"; HAVE_GD="yes", HAVE_GD="") diff --git a/dansguardian_log.c b/dansguardian_log.c index 8abd018..bd913f3 100644 --- a/dansguardian_log.c +++ b/dansguardian_log.c @@ -77,8 +77,7 @@ void dansguardian_log(void) sprintf(guard_ou,"%s/dansguardian.log",tmp); if(access(DansGuardianConf, R_OK) != 0) { - sprintf(msg,"Cannot open DansGuardian config file: %s",DansGuardianConf); - debuga(msg); + debuga("Cannot open DansGuardian config file: %s",DansGuardianConf); exit(1); } @@ -112,8 +111,7 @@ void dansguardian_log(void) printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]); exit(1); } - sprintf(msg,"%s DansGuardian %s: %s",urly,buf,loglocation); - debuga(msg); + debuga("%s DansGuardian %s: %s",urly,buf,loglocation); } if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) { @@ -153,10 +151,8 @@ void dansguardian_log(void) if(fp_guard) fclose(fp_guard); if(fp_ou) fclose(fp_ou); - if(debug) { - sprintf(msg,"%s: %s",text[54],guard_ou); - debuga(msg); - } + if(debug) + debuga("%s: %s",text[54],guard_ou); sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou); cstatus=system(tmp6); diff --git a/datafile.c b/datafile.c index 9b674c0..f0dea83 100644 --- a/datafile.c +++ b/datafile.c @@ -40,7 +40,6 @@ void data_file(char *tmp) char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50]; char ipantes[MAXLEN], nameantes[MAXLEN]; char accsmart[MAXLEN]; - char Msg[MAXLEN]; char wcrc[50]; char crc2[50]; char wdname[MAXLEN]; @@ -149,10 +148,8 @@ void data_file(char *tmp) } (void)closedir( dirp ); - if(debug) { - sprintf(Msg,"Datafile %s successfully",DataFile); - debuga(Msg); - } + if(debug) + debuga("Datafile %s successfully",DataFile); } void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache) diff --git a/decomp.c b/decomp.c index 50ca8a5..686b73b 100644 --- a/decomp.c +++ b/decomp.c @@ -32,14 +32,12 @@ void decomp(char *arq, char *zip, const char *tmp) int cstatus; if(access(arq, R_OK) != 0) { - sprintf(cmd,"%s: %s",text[64],arq); - debuga(cmd); + debuga("%s: %s",text[64],arq); exit(1); } if(strstr(arq,".gz") !=0) { - sprintf(cmd,"%s: %s > %s/sarg-file.in (zcat)",text[62],arq,tmp); - debuga(cmd); + debuga("%s: %s > %s/sarg-file.in (zcat)",text[62],arq,tmp); sprintf(cmd,"zcat %s > %s/sarg-file.in",arq,tmp); cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { @@ -53,8 +51,7 @@ void decomp(char *arq, char *zip, const char *tmp) } if(strstr(arq,".bz2") != 0) { - sprintf(cmd,"%s: %s > %s/sarg-file.in (bzcat)",text[62],arq,tmp); - debuga(cmd); + debuga("%s: %s > %s/sarg-file.in (bzcat)",text[62],arq,tmp); sprintf(cmd,"bzcat %s > %s/sarg-file.in",arq,tmp); cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { @@ -68,8 +65,7 @@ void decomp(char *arq, char *zip, const char *tmp) } if(strstr(arq,".Z")) { - sprintf(cmd,"%s: %s (uncompress)",text[62],arq); - debuga(cmd); + debuga("%s: %s (uncompress)",text[62],arq); sprintf(cmd,"uncompress %s",arq); cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { @@ -92,17 +88,15 @@ void recomp(const char *arq, const char *zip) int cstatus; if(access(arq, R_OK) != 0) { - sprintf(cmd,"%s: %s",text[64],arq); - debuga(cmd); + debuga("%s: %s",text[64],arq); exit(1); } if((strcmp(zip,"gzip") != 0) && (strcmp(zip,"compress") != 0)) return; - - sprintf(cmd,"%s: %s",text[63],arq); - debuga(cmd); + + debuga("%s: %s",text[63],arq); sprintf(cmd,"%s %s",zip,arq); cstatus=system(cmd); diff --git a/getconf.c b/getconf.c index f2fb8cc..c9d71c3 100644 --- a/getconf.c +++ b/getconf.c @@ -1097,10 +1097,8 @@ void getconf(void) FILE *fp_in; char buf[MAXLEN]; - if(debug) { - sprintf(Msg,"Loading configuration from: %s",ConfigFile); - debuga(Msg); - } + if(debug) + debuga("Loading configuration from: %s",ConfigFile); if ((fp_in = fopen(ConfigFile, "r")) == NULL) { fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile); diff --git a/html.c b/html.c index c88b6ef..7f42f41 100644 --- a/html.c +++ b/html.c @@ -285,10 +285,9 @@ void htmlrel(void) if(userip) { strcpy(u2,usuario); fixip(u2); - sprintf(msg, "%s: %s",text[61],u2); + debuga("%s: %s",text[61],u2); } else - sprintf(msg, "%s: %s",text[61],usuario); - debuga(msg); + debuga("%s: %s",text[61],usuario); } fscanf(fp_in,"%s",nacc); @@ -635,10 +634,8 @@ void htmlrel(void) fprintf(fp_usr,"%s\n",u2); fclose(fp_usr); - if(debug) { - sprintf(msg, "%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile); - debuga(msg); - } + if(debug) + debuga("%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile); } } } diff --git a/include/conf.h b/include/conf.h index 6a9063f..f9a2c71 100755 --- a/include/conf.h +++ b/include/conf.h @@ -79,6 +79,9 @@ gdPoint points[4]; #if HAVE_GDFONTG_H #include #endif +#if HAVE_STDARG_H +#include +#endif #if HAVE_FOPEN64 #define _FILE_OFFSET_BITS 64 diff --git a/include/defs.h b/include/defs.h index ea7d4e9..3f8a05c 100755 --- a/include/defs.h +++ b/include/defs.h @@ -132,7 +132,7 @@ void write_html_header(FILE *fp_ou, const char * ind); void write_html_trailer(FILE *fp_ou); char *subs(char *str, char *from, char *to); void conv_month(char *month); -void debuga(const char *msg); +void debuga(const char *msg,...); void debugaz(const char *head, const char *msg); void my_lltoa(unsigned long long int n, char s[], int len); char *get_size(const char *path, const char *file); diff --git a/index.c b/index.c index 22bd7cb..af32b5d 100644 --- a/index.c +++ b/index.c @@ -66,7 +66,7 @@ void make_index(void) return; } - if(debug) debuga(text[53]); + if(debug) debuga("%s",text[53]); // Root dir dirp = opendir(outdir); diff --git a/lastlog.c b/lastlog.c index 1c9a893..bdf4258 100644 --- a/lastlog.c +++ b/lastlog.c @@ -101,10 +101,8 @@ void mklastlog(const char *outdir) buf[strlen(buf)-1]='\0'; if(ftot) { - if(debug) { - sprintf(msg,"%s: %s",text[81],buf); - debuga(msg); - } + if(debug) + debuga("%s: %s",text[81],buf); // sprintf(temp,"%s%s",outdir,buf); sprintf(temp,"rm -r %s%s",outdir,buf); system(temp); diff --git a/log.c b/log.c index 58100b0..eb27ac3 100644 --- a/log.c +++ b/log.c @@ -422,8 +422,7 @@ int main(int argc,char *argv[]) if(ConfigFile[0] == '\0') sprintf(ConfigFile,"%s/sarg.conf",SYSCONFDIR); if(access(ConfigFile, R_OK) != 0) { - sprintf(msg,"Cannot open config file: %s - %s",ConfigFile,strerror(errno)); - debuga(msg); + debuga("Cannot open config file: %s - %s",ConfigFile,strerror(errno)); exit(1); } @@ -483,8 +482,7 @@ int main(int argc,char *argv[]) strcpy(hexclude,ExcludeHosts); if(strlen(hexclude) > 0) { if(access(hexclude, R_OK) != 0) { - sprintf(msg,"Cannot open exclude_hosts file: %s - %s",hexclude,strerror(errno)); - debuga(msg); + debuga("Cannot open exclude_hosts file: %s - %s",hexclude,strerror(errno)); exit(1); } gethexclude(hexclude,debug); @@ -648,10 +646,8 @@ int main(int argc,char *argv[]) printf("Language=%s\n\n",text[3]); } - if(debug){ - sprintf(msg,"sarg %s: %s",text[73],VERSION); - debuga(msg); - } + if(debug) + debuga("sarg %s: %s",text[73],VERSION); if (strlen(Ulimit) > 0) { #if defined(RLIMIT_NOFILE) @@ -670,15 +666,12 @@ int main(int argc,char *argv[]) #elif defined(RLIMIT_OFILE) if(setrlimit (RLIMIT_OFILE, &rl) == -1) { #endif - sprintf(msg,"setrlimit error - %s\n",strerror(errno)); - debuga(msg); + debuga("setrlimit error - %s\n",strerror(errno)); } } - if(debug) { - sprintf(msg,"Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING" max="RLIM_STRING,l1,l2,rl.rlim_cur,rl.rlim_max); - debuga(msg); - } + if(debug) + debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING" max="RLIM_STRING,l1,l2,rl.rlim_cur,rl.rlim_max); } read_usertab(UserTabFile); @@ -692,10 +685,8 @@ int main(int argc,char *argv[]) strcpy(arqtt,arq); decomp(arq,zip,tmp); - if(debug) { - sprintf(msg, "%s: %s",text[7],arq); - debuga(msg); - } + if(debug) + debuga("%s: %s",text[7],arq); if((fp_in=MY_FOPEN(arq,"r"))==NULL) { fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno)); @@ -1144,23 +1135,23 @@ int main(int argc,char *argv[]) tt=atoi(data); t=localtime(&tt); - strftime(tbuf2, 127, "%H%M", t); + strftime(tbuf2, sizeof(tbuf2), "%H%M", t); if(strncmp(df,"u",1) == 0) - strftime(tbuf, 127, "%Y%b%d", t); + strftime(tbuf, sizeof(tbuf), "%Y%b%d", t); if(strncmp(df,"e",1) == 0) - strftime(tbuf, 127, "%d%b%Y", t); + strftime(tbuf, sizeof(tbuf), "%d%b%Y", t); if(strncmp(df,"w",1) == 0) { strcpy(IndexTree,"file"); - strftime(tbuf, 127, "%Y.%U", t); + strftime(tbuf, sizeof(tbuf), "%Y.%U", t); } - strftime(dia, 127, "%d/%m/%Y", t); - strftime(wdata, 127, "%Y%m%d", t); + strftime(dia, sizeof(dia), "%d/%m/%Y", t); + strftime(wdata, sizeof(wdata), "%Y%m%d", t); idata=atoi(wdata); if(strncmp(df,"u",1)==0) - strftime(dia, 127, "%m/%d/%Y", t); + strftime(dia, sizeof(dia), "%m/%d/%Y", t); sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec); } else { strcpy(wtemp,data+1); @@ -1186,9 +1177,9 @@ int main(int argc,char *argv[]) } if(strcmp(df,"u") == 0) - sprintf(tbuf,"%s%s%s",ano,mes,dia); + snprintf(tbuf,sizeof(tbuf),"%s%s%s",ano,mes,dia); if(strcmp(df,"e") == 0) - sprintf(tbuf,"%s%s%s",dia,mes,ano); + snprintf(tbuf,sizeof(tbuf),"%s%s%s",dia,mes,ano); builddia(dia,mes,ano,df,wdata); idata=atoi(wdata); } @@ -1420,20 +1411,19 @@ int main(int argc,char *argv[]) fclose (fp_Write_User); if(debug) { - sprintf(msg, " %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx); - debuga(msg); + debuga(" %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx); if((common_log) && (squid_log)) - debuga(text[12]); + debuga("%s",text[12]); if((common_log) && (!squid_log)) - debuga(text[13]); + debuga("%s",text[13]); if((!common_log) && (squid_log)) - debuga(text[14]); + debuga("%s",text[14]); if(sarglog) - debuga(text[124]); + debuga("%s",text[124]); if((!common_log) && (!squid_log) && (!sarglog) && (!isalog)) { if(!totregsg) { @@ -1477,10 +1467,8 @@ int main(int argc,char *argv[]) debugaz("period",period); } - if(debug){ - sprintf(msg, "%s: %s",text[17],period); - debuga(msg); - } + if(debug) + debuga("%s: %s",text[17],period); fclose(fp_in); // fclose(fp_ou); @@ -1514,10 +1502,8 @@ int main(int argc,char *argv[]) } } - if(debug) { - sprintf(msg,"%s %s",text[123],arq_log); - debuga(msg); - } + if(debug) + debuga("%s %s",text[123],arq_log); } if(strstr(ReportType,"denied") != 0) { @@ -1562,7 +1548,7 @@ int main(int argc,char *argv[]) free(excludeuser); if(debug) - debuga(text[21]); + debuga("%s",text[21]); exit(0); @@ -1574,14 +1560,11 @@ static void getusers(const char *pwdfile, int debug) FILE *fp_usr; char buf[255]; - char Msg[255]; char *str; unsigned long int nreg=0; - if(debug) { - sprintf(Msg,"%s: %s",text[60],pwdfile); - debuga(Msg); - } + if(debug) + debuga("%s: %s",text[60],pwdfile); if ((fp_usr = fopen(pwdfile, "r")) == NULL) { fprintf(stderr, "SARG: (getusers) %s: %s - %s\n",text[45],pwdfile,strerror(errno)); @@ -1622,13 +1605,10 @@ void gethexclude(char *hexfile, int debug) FILE *fp_ex; char buf[255]; - char Msg[255]; unsigned long int nreg=0; - if(debug) { - sprintf(Msg,"%s: %s",text[67],hexfile); - debuga(Msg); - } + if(debug) + debuga("%s: %s",text[67],hexfile); if ((fp_ex = fopen(hexfile, "r")) == NULL) { fprintf(stderr, "SARG: (gethexclude) %s: %s - %s\n",text[45],hexfile,strerror(errno)); @@ -1667,13 +1647,10 @@ void getuexclude(char *uexfile, int debug) FILE *fp_ex; char buf[255]; - char Msg[255]; unsigned long int nreg=0; - if(debug) { - sprintf(Msg,"%s: %s",text[67],uexfile); - debuga(Msg); - } + if(debug) + debuga("%s: %s",text[67],uexfile); if ((fp_ex = fopen(uexfile, "r")) == NULL) { fprintf(stderr, "SARG: (gethexclude) %s: %s - %s\n",text[45],uexfile,strerror(errno)); diff --git a/report.c b/report.c index 0509b63..38275e6 100644 --- a/report.c +++ b/report.c @@ -391,8 +391,7 @@ static void maketmp(const char *user, const char *dirname, int debug, int indexo strcat(wdirname,user); if(debug){ - sprintf(msg,"%s: %s",text[49],wdirname); - debuga(msg); + debuga("%s: %s",text[49],wdirname); } strcat(wdirname,".utmp"); diff --git a/sort.c b/sort.c index 844be2b..3ee1d88 100644 --- a/sort.c +++ b/sort.c @@ -86,8 +86,7 @@ void tmpsort(void) strcat(arqin,direntp->d_name); if(debug) { - sprintf(msg,"%s: %s",text[54],arqou); - debuga(msg); + debuga("%s: %s",text[54],arqou); } strcat(arqou,".txt"); @@ -119,8 +118,7 @@ void sort_users_log(const char *tmp, int debug) int dlen; if(debug) { - sprintf(msg,"%s",text[138]); - debuga(msg); + debuga("%s",text[138]); } sprintf(wtmp,"%s/sarg",tmp); diff --git a/squidguard_log.c b/squidguard_log.c index 21c1759..79bc943 100644 --- a/squidguard_log.c +++ b/squidguard_log.c @@ -47,8 +47,7 @@ static void read_log(const char *wentp, FILE *fp_ou) printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",text[7]); exit(1); } - sprintf(msg,"%s squidGuard %s: %s",urly,buf,wentp); - debuga(msg); + debuga("%s squidGuard %s: %s",urly,buf,wentp); } /* With squidGuard, you can log groups in only one log file. @@ -225,8 +224,7 @@ void squidguard_log(void) if(strlen(SquidGuardConf) > 0) { if(access(SquidGuardConf, R_OK) != 0) { - sprintf(msg,"Cannot open squidGuard config file: %s",SquidGuardConf); - debuga(msg); + debuga("Cannot open squidGuard config file: %s",SquidGuardConf); exit(1); } @@ -282,8 +280,7 @@ void squidguard_log(void) if (fp_ou) fclose(fp_ou); if(debug) { - sprintf(msg,"%s: %s",text[54],guard_ou); - debuga(msg); + debuga("%s: %s",text[54],guard_ou); } sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou); diff --git a/useragent.c b/useragent.c index 23c553f..3518ac4 100644 --- a/useragent.c +++ b/useragent.c @@ -66,8 +66,7 @@ void useragent(void) } if(debug) { - sprintf(msg,"%s: %s",text[66],UserAgentLog); - debuga(msg); + debuga("%s: %s",text[66],UserAgentLog); } while(fgets(buf,sizeof(buf),fp_in)!=NULL) { @@ -107,8 +106,7 @@ void useragent(void) strcpy(fdate,data); if(debug) { - sprintf(msg, " %s: %ld",text[10],totregsl); - debuga(msg); + debuga(" %s: %ld",text[10],totregsl); } fclose(fp_in); @@ -119,8 +117,7 @@ void useragent(void) } if(debug) { - sprintf(msg,"%s: %s",text[54],tmp2); - debuga(msg); + debuga("%s: %s",text[54],tmp2); } sprintf(csort,"sort -n -t '\\' -k 4,4 -k 3,3 -k 2,2 -k 1,1 -o '%s' '%s'",tmp2,tmp3); @@ -144,7 +141,7 @@ void useragent(void) } if(debug) - debuga(text[72]); + debuga("%s",text[72]); fprintf(fp_ht, "\n\n\n \n",CharSet); fputs("\n",fp_ht); diff --git a/util.c b/util.c index 1b25165..807fe47 100644 --- a/util.c +++ b/util.c @@ -421,10 +421,15 @@ void fixper(char *tbuf, char *period, const char *duntil) } -void debuga(const char *msg) +void debuga(const char *msg,...) { - fprintf(stderr, "SARG: %s\n",msg); + va_list ap; + fputs("SARG: ",stderr); + va_start(ap,msg); + vfprintf(stderr,msg,ap); + va_end(ap); + fputc('\n',stderr); } @@ -765,7 +770,7 @@ void gperiod(void) fclose(fp_ou); if(debug) - debuga((char *)text[50]); + debuga("%s",(char *)text[50]); return; @@ -1137,8 +1142,7 @@ void removetmp(const char *outdir) return; if(debug) { - sprintf(msg,"%s: sarg-general, sarg-period",text[82]); - debuga(msg); + debuga("%s: sarg-general, sarg-period",text[82]); } sprintf(warea,"%s/sarg-general",outdir); if((fp_in=fopen(warea,"r"))==NULL){ @@ -1430,8 +1434,7 @@ void read_usertab(const char *UserTabFile) if (UserTabFile[0] != '\0') { if(debug) { - sprintf(msg,"%s: %s",text[86],UserTabFile); - debuga(msg); + debuga("%s: %s",text[86],UserTabFile); } if((fp_usr=fopen(UserTabFile,"r"))==NULL) { fprintf(stderr, "SARG: (log) %s: %s - %s\n",text[45],UserTabFile,strerror(errno)); -- 2.47.2