Content scan: Use ETIMEDOUT not ETIME, as having better portability. Bug 1640
[exim.git] / src / src / malware.c
index c13e70616da0b783081eab4ce975ac578e15cd21..141c6ea16c20e92f4f6722b83c01dc73a3c72768 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2003-2014 */
+/* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2003 - 2015 */
 /* License: GPL */
 
 /* Code for calling virus (malware) scanners. Called from acl.c. */
@@ -382,7 +382,6 @@ uschar * s;
 
 cd->retry = 0;
 while ((s = string_nextinlist(&optstr, subsep, NULL, 0)))
-  {
   if (Ustrncmp(s, "retry=", 6) == 0)
     {
     int sec = readconf_readtime((s += 6), '\0', FALSE);
@@ -392,7 +391,7 @@ while ((s = string_nextinlist(&optstr, subsep, NULL, 0)))
     }
   else
     return FAIL;
-  }
+return OK;
 }
 
 /*************************************************
@@ -880,14 +879,14 @@ if (!malware_ok)
 
        for (;;)
          {
-         errno = ETIME;
+         errno = ETIMEDOUT;
          i =  av_buffer+sizeof(av_buffer)-p;
          if ((bread= ip_recv(sock, p, i-1, tmo-time(NULL))) < 0)
            return m_errlog_defer_3(scanent,
              string_sprintf("unable to read result (%s)", strerror(errno)),
              sock);
 
-         for (p[bread] = '\0'; q = strchr(p, '\n'); p = q+1)
+         for (p[bread] = '\0'; q = Ustrchr(p, '\n'); p = q+1)
            {
            *q = '\0';
 
@@ -1098,17 +1097,16 @@ if (!malware_ok)
                      sizeof(linebuffer), tmo)))
        {
        if (rcnt < 0)
+         {
+         int err = errno;
          if (rcnt == -1)
            break;
-         else
-           {
-           int err = errno;
-           (void) pclose(scanner_out);
-           signal(SIGCHLD,eximsigchld); signal(SIGPIPE,eximsigpipe);
-           return m_errlog_defer(scanent, string_sprintf(
-               "unable to read from scanner (%s): %s",
-               commandline, strerror(err)));
-           }
+         (void) pclose(scanner_out);
+         signal(SIGCHLD,eximsigchld); signal(SIGPIPE,eximsigpipe);
+         return m_errlog_defer(scanent, string_sprintf(
+             "unable to read from scanner (%s): %s",
+             commandline, strerror(err)));
+         }
 
        if (Ustrlen(linebuffer) > fwrite(linebuffer, 1, Ustrlen(linebuffer), scanner_record))
          {
@@ -1214,7 +1212,7 @@ if (!malware_ok)
 * WITH_OLD_CLAMAV_STREAM is defined.
 * See Exim bug 926 for details.  */
 
-      uschar *p, *vname, *result_tag, *response_end;
+      uschar *p, *vname, *result_tag;
       int bread=0;
       uschar * file_name;
       uschar av_buffer[1024];
@@ -1297,7 +1295,7 @@ if (!malware_ok)
                      string_sprintf("missing port: '%s'", scanner_options));
            continue;
            }
-         cd->tcp_port = atoi(s);
+         cd->tcp_port = atoi(CS s);
 
          /* parse options */
          /*XXX should these options be common over scanner types? */
@@ -1616,10 +1614,9 @@ if (!malware_ok)
       while (isspace(*--p) && (p > av_buffer))
        *p = '\0';
       if (*p) ++p;
-      response_end = p;
 
       /* colon in returned output? */
-      if((p = Ustrchr(av_buffer,':')) == NULL)
+      if(!(p = Ustrchr(av_buffer,':')))
        return m_errlog_defer(scanent, string_sprintf(
                  "ClamAV returned malformed result (missing colon): %s",
                  av_buffer));