I wrote a program to read my apache HTTP logs and generate a .htaccess file banning ip's
which break the terms and conditions of my server.
I have had no problem for weeks until today.
My server was under heavy load (for me) with about 70 clients browsing at once.
I reviewed my logs and noted a violation of the t&c so I ran my .htaccess generator to update
the ban list. When I did the program produced some very unexpected output.
My client which done nothing to meet my ban criteria was included in the deny section of the
htaccess file.
I restored my previous ban listing and started debugging my program.
I've been able to reproduce the results. and determined the bug is a "race condition"
I'm using fstream.getline() to access the log file.
below is the portion of code which I believe the bug is in.
the full program can be seen here -Attachment 8747-
With a empty log file and a the program in an infinite loop I can cause the error by access my
test server with internet explorer.
I can't figure out why its happening.
Its like fstream.getline() is giving me the same line of input over and over.
Any advice???
i've compiled on vista64, vista32 and xp32Code:void GenerateBanList(char* argv[]){
char lineBuffer[1024];
char seed[] = "400 - ";
BanEntry tmp;
int x;
size_t size = 0;
size_t count;
#ifndef _DEBUG
//save space
#endif
AccessLog_file.clear();
AccessLog_file.open( argv[1], std::ios::in);
if( !AccessLog_file.is_open() ){
std::cout << " Error opening Access Log :" << argv[1] << "\n";
exit(0);
}
while( !AccessLog_file.eof() ){
memset(lineBuffer, 0, sizeof(lineBuffer));
/*error*/ AccessLog_file.getline(lineBuffer, sizeof(lineBuffer)-1);
count = AccessLog_file.gcount();
if( count == 0)
continue;
size+= count;
tmp = StringToBan(lineBuffer);
x = FindIpInVector(tmp);
switch(tmp.code){
case 400:
case 401:
case 404:
if(x == -1){
banlist.push_back(tmp);
}else{
banlist[x].count++;
#ifdef _DEBUG
//save space
#endif
}
break;
default:
break;
}
}
AccessLog_file.close();
if(size != LastFileSize){
IsModified = true;
LastFileSize = size;
std::cout << ".";
}
}
same issue.
Visual Studio 2003.net