[exim-cvs] malware: fix ClamAV file send corking

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] malware: fix ClamAV file send corking
Gitweb: https://git.exim.org/exim.git/commitdiff/e40f75b25322c11065dbade34e32ca177b10768c
Commit:     e40f75b25322c11065dbade34e32ca177b10768c
Parent:     b4d6cfa1dac6ac8175dec02cbb50fc57eb4b3acb
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sat Jan 16 21:00:34 2021 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sat Jan 16 23:11:59 2021 +0000


    malware: fix ClamAV file send corking
---
 src/src/malware.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)


diff --git a/src/src/malware.c b/src/src/malware.c
index b581a87..abe627d 100644
--- a/src/src/malware.c
+++ b/src/src/malware.c
@@ -1453,7 +1453,6 @@ badseek:  err = errno;
       uschar av_buffer[1024];
       uschar *hostname = US"";
       host_item connhost;
-      uschar *clamav_fbuf;
       int clam_fd, result;
       unsigned int fsize_uint;
       BOOL use_scan_command = FALSE;
@@ -1631,6 +1630,9 @@ badseek:  err = errno;
       if (!use_scan_command)
     {
     struct stat st;
+#ifdef EXIM_TCP_CORK
+    BOOL corked = TRUE;
+#endif
     /* New protocol: "zINSTREAM\n" followed by a sequence of <length><data>
     chunks, <n> a 4-byte number (network order), terminated by a zero-length
     chunk. */
@@ -1675,7 +1677,8 @@ badseek:  err = errno;


     /* send file size */
 #ifdef EXIM_TCP_CORK
-    (void) setsockopt(clam_fd, IPPROTO_TCP, EXIM_TCP_CORK, US &on, sizeof(on));
+    (void) setsockopt(malware_daemon_ctx.sock, IPPROTO_TCP, EXIM_TCP_CORK,
+              US &on, sizeof(on));
 #endif
     send_size = htonl(fsize_uint);
     if (send(malware_daemon_ctx.sock, &send_size, sizeof(send_size), 0) < 0)
@@ -1684,6 +1687,7 @@ badseek:  err = errno;
         malware_daemon_ctx.sock);


     /* send file body */
+    /*XXX sendfile? */
     while (fsize_uint)
       {
       unsigned n = MIN(fsize_uint, big_buffer_size);
@@ -1692,11 +1696,19 @@ badseek:  err = errno;
           string_sprintf("can't read spool file %s: %s",
         eml_filename, strerror(errno)),
           malware_daemon_ctx.sock);
-      if ((n = send(malware_daemon_ctx.sock, clamav_fbuf, n, 0)) < 0)
+      if (send(malware_daemon_ctx.sock, big_buffer, (size_t)n, 0) < 0)
         return m_panic_defer_3(scanent, NULL,
-          string_sprintf("unable to send file body to socket (%s)", hostname),
+          string_sprintf("unable to send file body to socket (%s): %s", hostname, strerror(errno)),
           malware_daemon_ctx.sock);
       fsize_uint -= n;
+#ifdef EXIM_TCP_CORK
+      if (corked)
+        {
+        corked = FALSE;
+        (void) setsockopt(malware_daemon_ctx.sock, IPPROTO_TCP, EXIM_TCP_CORK,
+                  US &off, sizeof(off));
+        }
+#endif
       }


     send_final_zeroblock = 0;
@@ -1704,9 +1716,6 @@ badseek:  err = errno;
       return m_panic_defer_3(scanent, NULL,
         string_sprintf("unable to send file terminator to socket (%s)", hostname),
         malware_daemon_ctx.sock);
-#ifdef EXIM_TCP_CORK
-    (void) setsockopt(clam_fd, IPPROTO_TCP, EXIM_TCP_CORK, US &off, sizeof(off));
-#endif
     }
       else
     { /* use scan command */