Patch for Sophie - Error: File could not be accessed

Patrick Clohessy <[email protected]> Fri, 11 Feb 2005 15:30:51 +0800
Newsgroups gmane.comp.security.virus.vtools
Message-ID <[email protected]>
Hi All

I was recently re-installing one of my servers with Fedora Core 3 and 
noticed a problem with Sophie 3.03 and 3.04rc2. When scanning a 
directory it would scan ".." and then recurse through my entire file 
system and produce "Error: File could not be accessed".

Taking a look at the code for sophie_scandir.c shows the following:

/* Let's get rid of '.' and '..' */
direntry = readdir(dirpt);
direntry = readdir(dirpt);

For some reason, which I'm yet to figure out,  under Fedora Core 3 and 
possible other OS's (however I can confirm it's fine under Fedora Core 
1) dirpt doesn't have "." and ".." as the first two elements as assumed 
by the above code.

I've attached a patch which will check each element to see whether it's 
either "." or ".." and if so to skip it. The code is:

while ((direntry = readdir(dirpt)))
{
    
if((strcmp(direntry->d_name,".")==0)||(strcmp(direntry->d_name,"..")==0))
    {
          continue;
    }
    .....
}

I have tested this patch with emails containing viruses and with emails 
containing no viruses and it appears to work correctly.

-- 
Patrick Clohessy
Curtin University of Technology
Department of Computing
Tel: +61 8 9266 7817
email: [email protected]

_______________________________________________
vtools mailing list
[email protected]
http://www.vanja.com/list/listinfo.cgi/vtools
patch.sophie_scandir.skipdotdot (text/plain, 625 B)
--- sophie_scandir.c.orginial	2005-02-11 15:06:19.545596743 +0800
+++ sophie_scandir.c	2005-02-11 15:09:03.513498364 +0800
@@ -34,11 +34,18 @@
 	}
 	
 	/* Let's get rid of '.' and '..' */
+/*
 	direntry = readdir(dirpt);
 	direntry = readdir(dirpt);
+*/
 
 	while ((direntry = readdir(dirpt)))
 	{
+		/* Let's get rid of '.' and '..' properly*/
+                if((strcmp(direntry->d_name,".")==0)||(strcmp(direntry->d_name,"..")==0))
+                {
+                        continue;
+                }
 		memset(path, 0, sizeof(path));
 		strncat(path, dirpath, sizeof(path)-1);
 		strncat(path, "/", sizeof(path)-1);