]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
A few string optimizations.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 7 Sep 2009 18:57:10 +0000 (18:57 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 7 Sep 2009 18:57:10 +0000 (18:57 +0000)
Truncate the user name at the %20 instead of the first % if a %20 is found somewhere in the user name.

log.c

diff --git a/log.c b/log.c
index 3092133be048b8828a2b7dfbc54c7a388c850747..d8ec5f7c765c93d125370465f05722a053ea504a 100644 (file)
--- a/log.c
+++ b/log.c
@@ -804,8 +804,8 @@ int main(int argc,char *argv[])
                printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
                exit(1);
             }
-            if((str=(char *) strstr(data, ".")) != (char *) NULL ) {
-               if((str=(char *) strstr(str+1, ".")) != (char *) NULL ) {
+            if((str=(char *) strchr(data, '.')) != (char *) NULL ) {
+               if((str=(char *) strchr(str+1, '.')) != (char *) NULL ) {
                   strcpy(ip,data);
                   strcpy(elap,"0");
                   if(squid24) {
@@ -826,7 +826,7 @@ int main(int argc,char *argv[])
                      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                      exit(1);
                   }
-                  if((str=(char *) strstr(bufz, " ")) != (char *) NULL ) {
+                  if((str=(char *) strchr(bufz, ' ')) != (char *) NULL ) {
                      if (getword(code,sizeof(code),bufz,' ')<0) {
                         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                         exit(1);
@@ -1046,12 +1046,17 @@ int main(int argc,char *argv[])
          if(testvaliduserchar(user))
             continue;
 
-         if(strstr(user,"%20") != 0) {
-            if (getword(w,sizeof(w),user,'%')<0) {
-               printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-               exit(1);
-            }
-            strcpy(user,w);
+         if((str = strstr(user,"%20")) != NULL) {
+            /*
+            Why is it necessary to truncate the user name at the first space ?
+
+            The old code used to truncate the user name at the first % if a %20 was
+            found anywhere in the string. That means the string could be truncated
+            at the wrong place if another % occured before the %20. This new code should
+            avoid that problem and only truncate at the space. There is no bug
+            report indicating that anybody noticed this.
+            */
+            *str='\0';
          }
 
          while(strstr(user,"%5c") != 0) {
@@ -1102,7 +1107,10 @@ int main(int argc,char *argv[])
                printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
                exit(1);
             }
-            /*if (!strchr(url,'/')) {
+            /*
+            This code rejects any host without a directory. Now it
+            doesn't look necessary so it is commented out.
+            if (!strchr(url,'/')) {
                if (debugm) printf("URL without directory: %s\n",url);
                totregsx++;
                continue;