samba-vscan/clamav vscan-clamav_core.c,1.5.2.8,1.5.2.9

Rainer Link <[email protected]> Thu, 09 Sep 2004 13:10:58 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/clamav
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9132

Modified Files:
      Tag: VSCAN_0_3
	vscan-clamav_core.c 
Log Message:
simplified daemon version of scanfile

Patch by Helmut


Index: vscan-clamav_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav_core.c,v
retrieving revision 1.5.2.8
retrieving revision 1.5.2.9
diff -u -d -r1.5.2.8 -r1.5.2.9
--- vscan-clamav_core.c	9 Sep 2004 13:02:53 -0000	1.5.2.8
+++ vscan-clamav_core.c	9 Sep 2004 13:10:56 -0000	1.5.2.9
@@ -113,9 +113,7 @@
 {
     char *request = NULL;
     size_t len = 0;
-    int response = 0;
     char buff[1024];   
-    char *vir = NULL, *p1 = NULL;
     FILE *fpin;
 
     /* open stream sockets */
@@ -141,50 +139,44 @@
     safe_strcpy(request, "SCAN ", len-1);
     safe_strcat(request, scan_file, len-1); 
     if (write(sockfd, request, strlen(request)) != strlen(request)) {
-        if (request) {
-            free(request);
-        }
+        free(request);
+
         vscan_syslog("ERROR: can not write to the clamd socket");
         return -1; /* error writing to the clamd socket */
     }
 
-    if (request) {
-        free(request);
-    }
+    free(request);
 
     if (fgets((char *)&buff, sizeof(buff), fpin) > 0) {
+        char *p1;
         fclose(fpin);
         /* virus found */    
         if ((p1 = strstr(buff, "FOUND\n"))) {
-            response = 1;
+            char *vir;
     
             vir = strchr(buff, ':') + 1;
-            p1--;
 
             /* remove trailing and beginning spaces */
-            while ((isspace((int)*p1)) && (p1 >= vir)) {
-                *p1-- = '\0';
-            }
-            while (isspace((int)*vir)) {
+            while (isspace((int)*vir))
                 vir++;
-            }
-        
+            for (--p1; (p1 >= vir) && (isspace((int)*p1)); p1--);
+            p1[1] = '\0';
+
             vscan_clamav_log_virus(scan_file, vir, client_ip);
             return 1;
         }
-	if ((p1 = strstr(buff, "OK\n"))) {
-            if (verbose_file_logging) {
+	if ((NULL !=  strstr(buff, "OK\n"))) {
+            if (verbose_file_logging)
                 vscan_syslog("INFO: file %s is clean", scan_file);
-            }
+
             return 0;
         }
 
         vscan_syslog("ERROR: file %s not found, not readable or an error occured", scan_file);
         return -2;
     }
-    else if (fpin) {
-        fclose(fpin);
-    }
+
+    fclose(fpin);
 
     vscan_syslog("ERROR: can not get result from clamd");
     return -1;



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click