From: Frédéric Marchal Date: Mon, 7 Sep 2009 18:57:10 +0000 (+0000) Subject: A few string optimizations. X-Git-Tag: v2_2_6~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ff563a220b5fce938ab67e0528ad853ffdded1b;p=thirdparty%2Fsarg.git A few string optimizations. Truncate the user name at the %20 instead of the first % if a %20 is found somewhere in the user name. --- diff --git a/log.c b/log.c index 3092133..d8ec5f7 100644 --- 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;