Avast: rework interface exim-4_91_RC3
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Mon, 2 Apr 2018 20:11:57 +0000 (22:11 +0200)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Mon, 2 Apr 2018 20:12:46 +0000 (22:12 +0200)
src/src/malware.c

index 730a2be..479c3db 100644 (file)
@@ -2047,26 +2047,13 @@ b_seek:   err = errno;
 
            case AVA_RSP:
 
-             if (isdigit(buf[0]))
-               { /* we're done, this is the last response line from the scanner */
-                DEBUG(D_acl) debug_printf_indent("sent to avast QUIT\n");
-               if (send(sock, "QUIT\n", 5, 0) == -1) /* courtesy */
-                 return m_panic_defer_3(scanent, CUS callout_address,
-                         string_sprintf(
-                             "unable to send quit request to socket (%s): %s",
-                             scanner_options, strerror(errno)),
-                             sock);
-
-                if (buf[0] != '2') error_message = buf;
-               avast_stage = AVA_DONE;
+             if (isdigit(buf[0]))  /* We're done */
                 goto endloop;
-               }
 
-              if (malware_name) /* nothing else matters, just read on */
+              if (malware_name)     /* Nothing else matters, just read on */
                 break;
 
-             if (pcre_exec(ava_re_clean, NULL, CS buf, slen,
-                   0, 0, ovector, nelem(ovector)) > 0)
+             if (pcre_exec(ava_re_clean, NULL, CS buf, slen, 0, 0, NULL, 0) == 0)
                break;
 
               if (malware_name = m_pcre_exec(ava_re_virus, buf))
@@ -2077,15 +2064,17 @@ b_seek:   err = errno;
                 break;
                 }
 
-              if (strict && (malware_name = m_pcre_exec(ava_re_error, buf)))
+              if (strict)           /* treat scanner errors as malware */
                 {
-                unescape(malware_name);
-                DEBUG(D_acl)
-                  debug_printf_indent("unescaped error message: '%s'\n", malware_name);
-                break;
+                if (malware_name = m_pcre_exec(ava_re_error, buf))
+                  {
+                  unescape(malware_name);
+                  DEBUG(D_acl)
+                    debug_printf_indent("unescaped error message: '%s'\n", malware_name);
+                  break;
+                  }
                 }
-
-              if (pcre_exec(ava_re_error, NULL, CS buf, slen, 0, 0, NULL, 0) == 0)
+              else if (pcre_exec(ava_re_error, NULL, CS buf, slen, 0, 0, NULL, 0) == 0)
                 {
                 log_write(0, LOG_MAIN, "internal scanner error (ignored): %s", buf);
                 break;
@@ -2093,7 +2082,7 @@ b_seek:   err = errno;
 
              /* here also for any unexpected response from the scanner */
               DEBUG(D_acl) debug_printf("avast response not handled: '%s'\n", buf);
-              error_message = string_sprintf(string_sprintf("unexpected response from scanner: '%s'", buf));
+
              goto endloop;
 
            default:    log_write(0, LOG_PANIC, "%s:%d:%s: should not happen",
@@ -2101,23 +2090,23 @@ b_seek:   err = errno;
            }
          }
        }
+
       endloop:
 
-      switch(avast_stage)
-       {
-       case AVA_HELO:
-       case AVA_OPT:
-       case AVA_RSP:
-                        if (nread == -1) error_message = "EOF from scanner";
-                        else if (nread < 0) error_message = "timeout from scanner";
+      if (nread == -1) error_message = "EOF from scanner";
+      else if (nread < 0) error_message = "timeout from scanner";
+      else if (nread == 0) error_message = "got nothing from scanner";
+      else if (buf[0] != '2') error_message = buf;
 
-        case AVA_DONE:
-                        if (error_message)
-                          return m_panic_defer_3(scanent, CUS callout_address, error_message, sock);
+      DEBUG(D_acl) debug_printf_indent("sent to avast QUIT\n");
+      if (send(sock, "QUIT\n", 5, 0) == -1)
+        return m_panic_defer_3(scanent, CUS callout_address,
+          string_sprintf("unable to send quit request to socket (%s): %s",
+            scanner_options, strerror(errno)), sock);
+
+      if (error_message)
+        return m_panic_defer_3(scanent, CUS callout_address, error_message, sock);
 
-       default:        break;
-       }
-      break;
       }
 #endif
   }    /* scanner type switch */