]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Protect ip2name against buffer overflows and replace characters that are valid in...
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 26 Jun 2009 13:36:39 +0000 (13:36 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 26 Jun 2009 13:36:39 +0000 (13:36 +0000)
17 files changed:
authfail.c
dansguardian_report.c
datafile.c
denied.c
download.c
grepday.c
html.c
include/conf.h
ip2name.c
log.c
realtime.c
repday.c
report.c
siteuser.c
squidguard_report.c
topuser.c
useragent.c

index d4a5a88f77dd1a6edfd6f61c8c296d4dc2823a1b..843d60265b87cfeb49651b0e5dd18bf8b738352e 100644 (file)
@@ -139,7 +139,7 @@ void authfail_report()
       }
 
       if(strcmp(Ip2Name,"yes") == 0) 
-         ip2name(ip);
+         ip2name(ip,sizeof(ip));
 
       if(!z) {
          strcpy(ouser,user);
index 3b80de4b2169db0b6ce1fd83620cdf7112279026..b87c662cb224808e184a49abdef4ab749b7bd0d7 100644 (file)
@@ -146,7 +146,7 @@ void dansguardian_report()
       }
 
       if(strcmp(Ip2Name,"yes") == 0) 
-         ip2name(ip);
+         ip2name(ip,sizeof(ip));
 
       if(!z) {
          strcpy(ouser,user);
index 3df03fe2ac3de788c122caf5cd8acad2d149fbe2..c94ec408145db923a60d6e538eb8fd465adfa145 100644 (file)
@@ -95,7 +95,7 @@ void data_file(char *tmp)
          if(strcmp(Ip2Name,"yes") == 0) {
             if(strcmp(accip,ipantes) != 0) {
                strcpy(ipantes,accip);
-               ip2name(accip);
+               ip2name(accip,sizeof(accip));
                strcpy(nameantes,accip);
             } 
            else strcpy(accip,nameantes);
index e793146f968de44c1e23b3dbcecae20f54be9371..21f20dd3d1e073d58bb9684ee8c3c82fe1f9d1f9 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -124,7 +124,7 @@ void gen_denied_report()
       }
 
       if(strcmp(Ip2Name,"yes") == 0) 
-         ip2name(ip);
+         ip2name(ip,sizeof(ip));
 
       if(!z) {
          strcpy(ouser,user);
index a9a0df6492be300af54ed074b292bed71441fd7a..bb3c56ae2d5cc08690437429750d991a5a550dc8 100644 (file)
@@ -131,7 +131,7 @@ void download_report()
       }
 
       if(strcmp(Ip2Name,"yes") == 0) 
-         ip2name(ip);
+         ip2name(ip,sizeof(ip));
 
       if(!z) {
          strcpy(ouser,user);
index af67fe3749d352937342c5784c7b4d4564a945e5..2b2153b51de264eb4b345192552de7d44c9962c7 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -407,7 +407,7 @@ void greport_day(char *user, int *iprel, int *ipuser)
    if(strcmp(Ip2Name,"yes") == 0)
       if((str=(char *) strstr(name, ".")) != (char *) NULL) {
          if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
-            ip2name(wuser);
+            ip2name(wuser,sizeof(wuser));
    }
 
    if(UserTabFile[0] != '\0') {
diff --git a/html.c b/html.c
index ac4fdf1fb12795a42a664ba8f0c1bb7a6612fabe..70b8c2d6ab9e979a3fb3bc469749ede741ecdc1d 100644 (file)
--- a/html.c
+++ b/html.c
@@ -233,7 +233,7 @@ void htmlrel()
          fixip(u2);
       }
       if(strcmp(Ip2Name,"yes") == 0)
-         ip2name(u2);
+         ip2name(u2,sizeof(u2));
 
       if(UserTabFile[0] != '\0') {
          sprintf(warea,":%s:",u2);
@@ -397,8 +397,9 @@ void htmlrel()
             }
             strcpy(siteind,urly);
             str=siteind;
-            for(z1=0; z1<strlen(str); z1++) {
-              if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
+            for(z1=0; str[z1]; z1++) {
+               if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' ||
+                  str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$')
                   str[z1]='_';
             }
             sprintf(href2,"<a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\"></a>",usuario,siteind,tmp6,ltext110,text[55]);
index 2aaf653f6918820922d9395457616de0085753b8..faae954a928ae01be2c248feef286f7e7f8a2e99 100755 (executable)
@@ -351,6 +351,6 @@ int getword(char *word, int limit, char *line, int stop);
 int getword_multisep(char *word, int limit, char *line, int stop);
 int getword3(char *word, int limit, char *line, int stop);
 void name_month(char *month,int month_len);
-
+void ip2name(char *ip,int ip_len);
 
       
\ No newline at end of file
index 3f7c4095d233e7c5d1857823537555b247967518..1907130ec2de1fea2db8ec3199e23af1b6be6291 100644 (file)
--- a/ip2name.c
+++ b/ip2name.c
@@ -25,7 +25,7 @@
 
 #include "include/conf.h"
 
-void ip2name(char *ip)
+void ip2name(char *ip,int ip_len)
 { 
    u_long addr;
    struct hostent *hp; 
@@ -42,7 +42,8 @@ void ip2name(char *ip)
       struct in_addr in; 
 
       (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));         
-      (void) sprintf(ip,"%s", hp->h_name); 
+      strncpy(ip,hp->h_name,ip_len-1);
+      ip[ip_len-1]=0;
    } 
 
    return;
diff --git a/log.c b/log.c
index 258ecc98955f86603b17afa6b75237e237cdaa80..e837f682c680668159a1d5d2414d3e1bef833ca8 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1127,7 +1127,7 @@ int main(argc,argv)
         }
 
        str=user;
-       for(z1=0; z1<strlen(str); z1++) {
+       for(z1=0; str[z1]; z1++) {
           if(isalnum(str[z1]) || ispunct(str[z1])) {
           if(str[z1]=='.') dotinuser++;
           if(str[z1]=='?' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
index 5f0be08900a0946094cd8612acc2829c1d675841..6b71f5f5b6a1f9c37a3245be6737c16ceaf1e365 100755 (executable)
@@ -237,7 +237,7 @@ void datashow(char *tmp)
 
       strcpy(u2,user);
       if(strcmp(Ip2Name,"yes") == 0)
-         ip2name(u2);
+         ip2name(u2,sizeof(u2));
       if(UserTabFile[0] != '\0') {
          sprintf(warea,":%s:",u2);
          if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
index 9c13b81ca25ddb7552bd83e1cfece3e745f84184..aa0bafc4cb380aad94354fce0f1a1a40b8119012 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -96,7 +96,7 @@ void report_day(char *user, int *iprel, int *ipuser)
    if(strcmp(Ip2Name,"yes") == 0)
       if((str=(char *) strstr(name, ".")) != (char *) NULL) {
          if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
-            ip2name(wuser);
+            ip2name(wuser,sizeof(wuser));
    }
 
    if(UserTabFile[0] != '\0') {
index d06903252e00b18848dc71a0c0ead81f0c7ea8de..10d790df9f66fa3b77cb5102e376a5275fe8db60 100644 (file)
--- a/report.c
+++ b/report.c
@@ -128,7 +128,7 @@ void gerarel()
          if(strcmp(Ip2Name,"yes") == 0) {
             if(strcmp(accip,ipantes) != 0) {
                strcpy(ipantes,accip);
-               ip2name(accip);
+               ip2name(accip,sizeof(accip));
                strcpy(nameantes,accip);
             } else strcpy(accip,nameantes);
          }
@@ -193,10 +193,11 @@ void gerarel()
             ind2++;
            strcpy(siteind,accurl);
            str=siteind;
-           for(z1=0; z1<strlen(str); z1++) {
-           if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
-                            str[z1]='_';
-            }
+           for(z1=0; str[z1]; z1++) {
+              if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' ||
+              str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$')
+                 str[z1]='_';
+        }
            sprintf(arqtt,"%s/%s",dirname,accuser);
            if(access(arqtt, R_OK) != 0)
                my_mkdir(arqtt);
@@ -240,7 +241,7 @@ void gerarel()
 
             strcpy(u2,user);
             if(strcmp(Ip2Name,"yes") == 0)
-               ip2name(u2);
+               ip2name(u2,sizeof(u2));
             if(UserTabFile[0] != '\0') {
                sprintf(warea,":%s:",u2);
                if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
index c300cc927a9e70b59d2b0d74ee183c76beaf6aa2..261644a5f16f5cdefb9a146959114255a8997aa2 100644 (file)
@@ -157,10 +157,10 @@ void siteuser()
       }
 
       if(strcmp(Ip2Name,"yes") == 0)
-         ip2name(user);
+         ip2name(user,sizeof(user));
 
       if(strcmp(Ip2Name,"yes") == 0)
-         ip2name(user);
+         ip2name(user,sizeof(user));
 
       if (getword(nacc,sizeof(nacc),buf,' ')<0){
          printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2);
index 8b0cb5e0a6780ba9361d7f7a70680a79d111137a..ada1d4504f894e4c0fc66616791487e735d842ea 100644 (file)
@@ -138,7 +138,7 @@ void squidguard_report()
       }
 
       if(strcmp(Ip2Name,"yes") == 0) 
-         ip2name(ip);
+         ip2name(ip,sizeof(ip));
 
       if(!z) {
          strcpy(ouser,user);
index 9a230d5f1d50a8749f207019e7c781ed9c0ac3cd..d172ef99d18df50eaca87397f774ad2cb0a4d50a 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -408,7 +408,7 @@ int topuser()
          if(strcmp(Ip2Name,"yes") == 0) {
             if(strcmp(user2,ipantes) != 0) {
                strcpy(ipantes,user2);
-               ip2name(user2);
+               ip2name(user2,sizeof(user2));
                strcpy(nameantes,user2);
             } else strcpy(user2,nameantes);
          }
@@ -445,7 +445,7 @@ int topuser()
       if((strcmp(Ip2Name,"yes") == 0) && 
         ((str=(char *) strstr(name, ".")) != (char *) NULL) && 
        ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
-               ip2name(name);
+               ip2name(name,sizeof(name));
 
       twork=my_atoll(nacc);
       my_lltoa(twork,nacc,0);
index 4d47da95c1f9b92f7f1264fb1a26c2ac24a7182f..15ed405ef2e902ade9c37767fb2cf814d56fda39 100644 (file)
@@ -184,7 +184,7 @@ void useragent()
       if(strcmp(Ip2Name,"yes") == 0) {
          if(strcmp(ip,ipbefore) != 0) {
             strcpy(ipbefore,ip);
-            ip2name(ip);
+            ip2name(ip,sizeof(ip));
             strcpy(namebefore,ip);
          } else strcpy(ip,namebefore);
       }