X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/94a18f283972b276150cdf72fef47e56512c11d7..1ac6b2e7857d7b6645dbd09047c4c2ac3b6cef1d:/src/src/malware.c diff --git a/src/src/malware.c b/src/src/malware.c index eb0c33cea..994c62993 100644 --- a/src/src/malware.c +++ b/src/src/malware.c @@ -1,5 +1,3 @@ -/* $Cambridge: exim/src/src/malware.c,v 1.21 2010/06/07 00:12:42 pdp Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ @@ -71,17 +69,22 @@ Returns: Exim message processing code (OK, FAIL, DEFER, ...) int malware(uschar **listptr) { uschar scan_filename[1024]; BOOL fits; + int ret; fits = string_format(scan_filename, sizeof(scan_filename), CS"%s/scan/%s/%s.eml", spool_directory, message_id, message_id); if (!fits) { + av_failed = TRUE; log_write(0, LOG_MAIN|LOG_PANIC, "malware filename does not fit in buffer [malware()]"); return DEFER; } - return malware_internal(listptr, scan_filename, FALSE); + ret = malware_internal(listptr, scan_filename, FALSE); + if (ret == DEFER) av_failed = TRUE; + + return ret; } @@ -112,7 +115,7 @@ malware_in_file(uschar *eml_filename) { /* spool_mbox() assumes various parameters exist, when creating the relevant directory and the email within */ (void) string_format(message_id_buf, sizeof(message_id_buf), - "dummy-%d", pseudo_random_number(INT_MAX)); + "dummy-%d", vaguely_random_number(INT_MAX)); message_id = message_id_buf; sender_address = US"malware-sender@example.net"; return_path = US""; @@ -128,6 +131,9 @@ malware_in_file(uschar *eml_filename) { set, but if that changes, then it should apply to these tests too */ unspool_mbox(); + /* silence static analysis tools */ + message_id = NULL; + return ret; } @@ -592,7 +598,7 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) } } else { - char *drweb_s = NULL; + const char *drweb_s = NULL; if (drweb_rc & DERR_READ_ERR) drweb_s = "read error"; if (drweb_rc & DERR_NOMEMORY) drweb_s = "no memory"; @@ -1068,7 +1074,7 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) cmdline_trigger_re = pcre_compile(CS cmdline_trigger, PCRE_COPT, (const char **)&rerror, &roffset, NULL); if (cmdline_trigger_re == NULL) { log_write(0, LOG_MAIN|LOG_PANIC, - "malware acl condition: regular expression error in '%s': %s at offset %d", cmdline_trigger_re, rerror, roffset); + "malware acl condition: regular expression error in '%s': %s at offset %d", cmdline_trigger, rerror, roffset); return DEFER; }; @@ -1086,7 +1092,7 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) cmdline_regex_re = pcre_compile(CS cmdline_regex, PCRE_COPT, (const char **)&rerror, &roffset, NULL); if (cmdline_regex_re == NULL) { log_write(0, LOG_MAIN|LOG_PANIC, - "malware acl condition: regular expression error in '%s': %s at offset %d", cmdline_regex_re, rerror, roffset); + "malware acl condition: regular expression error in '%s': %s at offset %d", cmdline_regex, rerror, roffset); return DEFER; }; @@ -1208,7 +1214,7 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) sizeof(sophie_options_buffer))) == NULL) { /* no options supplied, use default options */ sophie_options = sophie_options_default; - }; + } /* open the sophie socket */ sock = socket(AF_UNIX, SOCK_STREAM, 0); @@ -1243,14 +1249,14 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) DEBUG(D_acl) debug_printf("Malware scan: issuing %s scan [%s]\n", scanner_name, sophie_options); - if (write(sock, file_name, Ustrlen(file_name)) < 0) { + if ( write(sock, file_name, Ustrlen(file_name)) < 0 + || write(sock, "\n", 1) != 1 + ) { (void)close(sock); log_write(0, LOG_MAIN|LOG_PANIC, "malware acl condition: unable to write to sophie UNIX socket (%s)", sophie_options); return DEFER; - }; - - (void)write(sock, "\n", 1); + } /* wait for result */ memset(av_buffer, 0, sizeof(av_buffer)); @@ -1259,7 +1265,7 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) log_write(0, LOG_MAIN|LOG_PANIC, "malware acl condition: unable to read from sophie UNIX socket (%s)", sophie_options); return DEFER; - }; + } (void)close(sock); @@ -1277,7 +1283,7 @@ static int malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) else { /* all ok, no virus */ malware_name = NULL; - }; + } } /* ----------------------------------------------------------------------- */ @@ -1910,14 +1916,14 @@ static int mksd_parse_line (char *line) static int mksd_scan_packed(int sock, uschar *scan_filename) { struct iovec iov[3]; - char *cmd = "MSQ\n"; + const char *cmd = "MSQ\n"; uschar av_buffer[1024]; - iov[0].iov_base = cmd; + iov[0].iov_base = (void *) cmd; iov[0].iov_len = 3; iov[1].iov_base = CS scan_filename; iov[1].iov_len = Ustrlen(scan_filename); - iov[2].iov_base = cmd + 3; + iov[2].iov_base = (void *) (cmd + 3); iov[2].iov_len = 1; if (mksd_writev (sock, iov, 3) < 0)