From 33221042ea98f2a867b284ad3d88aab2a543a04e Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 18 Feb 2014 21:26:13 +0000 Subject: [PATCH] Fix up string types --- src/src/acl.c | 5 ++- src/src/expand.c | 6 +-- src/src/functions.h | 4 +- src/src/ip.c | 2 +- src/src/malware.c | 103 +++++++++++++++++++++----------------------- 5 files changed, 55 insertions(+), 65 deletions(-) diff --git a/src/src/acl.c b/src/src/acl.c index f25debd93..fe186ab34 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -2895,13 +2895,14 @@ if (r == HOST_FIND_FAILED || r == HOST_FIND_AGAIN) HDEBUG(D_acl) debug_printf("udpsend [%s]:%d %s\n", h->address, portnum, arg); -r = s = ip_connectedsocket(SOCK_DGRAM, h->address, portnum, 1, NULL, &errstr); +r = s = ip_connectedsocket(SOCK_DGRAM, h->address, portnum, portnum, + 1, NULL, &errstr); if (r < 0) goto defer; len = Ustrlen(arg); r = send(s, arg, len, 0); if (r < 0) { - errstr = strerror(errno); + errstr = US strerror(errno); close(s); goto defer; } diff --git a/src/src/expand.c b/src/src/expand.c index 30735db61..78b69cd39 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -4497,10 +4497,7 @@ while (*s != 0) if (Ustrncmp(sub_arg[0], "inet:", 5) == 0) { - BOOL connected = FALSE; - int namelen, port; - host_item shost; - host_item *h; + int port; uschar *server_name = sub_arg[0] + 5; uschar *port_name = Ustrrchr(server_name, ':'); @@ -5286,7 +5283,6 @@ while (*s != 0) uschar *list, *expr, *temp; uschar *save_iterate_item = iterate_item; uschar *save_lookup_value = lookup_value; - BOOL dummy; while (isspace(*s)) s++; if (*s++ != '{') goto EXPAND_FAILED_CURLY; diff --git a/src/src/functions.h b/src/src/functions.h index f646d25cf..a2e0aeaef 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -171,8 +171,8 @@ extern int host_scan_for_local_hosts(host_item *, host_item **, BOOL *); extern void invert_address(uschar *, uschar *); extern int ip_bind(int, int, uschar *, int); extern int ip_connect(int, int, uschar *, int, int); -extern int ip_connected_socket(int, const uschar *, int, int, int, - uschar **); +extern int ip_connectedsocket(int, const uschar *, int, int, + int, host_item *, uschar **); extern int ip_get_address_family(int); extern void ip_keepalive(int, uschar *, BOOL); extern int ip_recv(int, uschar *, int, int); diff --git a/src/src/ip.c b/src/src/ip.c index 6706b4479..a820998ca 100644 --- a/src/src/ip.c +++ b/src/src/ip.c @@ -269,7 +269,7 @@ ip_connectedsocket(int type, const uschar * hostname, int portlo, int porthi, int namelen, port; host_item shost; host_item *h; -int af, fd, fd4 = -1, fd6 = -1; +int af = 0, fd, fd4 = -1, fd6 = -1; shost.next = NULL; shost.address = NULL; diff --git a/src/src/malware.c b/src/src/malware.c index 93e30c06f..f3f624a4c 100644 --- a/src/src/malware.c +++ b/src/src/malware.c @@ -162,7 +162,7 @@ malware_errlog_defer(const uschar * str) } static int -m_scanner_errlog_defer(const uschar * scanner, const uschar * str) +m_scanner_errlog_defer(const char * scanner, const uschar * str) { return malware_errlog_defer(string_sprintf("%s: %s", scanner, str)); } @@ -264,7 +264,7 @@ m_unixsocket(const uschar * path, uschar ** errstr) struct sockaddr_un server; if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - *errstr = "can't open UNIX socket."; + *errstr = US"can't open UNIX socket."; return -1; } @@ -301,7 +301,7 @@ m_pcre_compile(const uschar * re, uschar ** errstr) int roffset; const pcre * cre; - cre = pcre_compile(re, PCRE_COPT, (const char **)&rerror, &roffset, NULL); + cre = pcre_compile(CS re, PCRE_COPT, (const char **)&rerror, &roffset, NULL); if (!cre) *errstr= string_sprintf("regular expression error in '%s': %s at offset %d", re, rerror, roffset); @@ -329,7 +329,7 @@ m_pcre_nextinlist(uschar ** list, int * sep, char * listerr, uschar ** errstr) if (!(list_ele = string_nextinlist(list, sep, NULL, 0))) *errstr = US listerr; else - cre = m_pcre_compile(CS list_ele, errstr); + cre = m_pcre_compile(CUS list_ele, errstr); return cre; } @@ -346,15 +346,15 @@ static struct scan const char * options_default; } m_scans[] = { - { M_FPROTD, "f-protd", "localhost 10200-10204" }, - { M_DRWEB, "drweb", "/usr/local/drweb/run/drwebd.sock" }, - { M_AVES, "aveserver", "/var/run/aveserver" }, - { M_FSEC, "fsecure", "/var/run/.fsav" }, - { M_KAVD, "kavdaemon", "/var/run/AvpCtl" }, + { M_FPROTD, "f-protd", CUS"localhost 10200-10204" }, + { M_DRWEB, "drweb", CUS"/usr/local/drweb/run/drwebd.sock" }, + { M_AVES, "aveserver", CUS"/var/run/aveserver" }, + { M_FSEC, "fsecure", CUS"/var/run/.fsav" }, + { M_KAVD, "kavdaemon", CUS"/var/run/AvpCtl" }, { M_CMDL, "cmdline", NULL }, - { M_SOPHIE, "sophie", "/var/run/sophie" }, - { M_CLAMD, "clamd", "/tmp/clamd" }, - { M_SOCK, "sock", "/tmp/malware.sock" }, + { M_SOPHIE, "sophie", CUS"/var/run/sophie" }, + { M_CLAMD, "clamd", CUS"/tmp/clamd" }, + { M_SOCK, "sock", CUS"/tmp/malware.sock" }, { M_MKSD, "mksd", NULL }, { -1, NULL, NULL } /* end-marker */ }; @@ -388,7 +388,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) /* make sure the eml mbox file is spooled up */ if (!(mbox_file = spool_mbox(&mbox_size, faking ? eml_filename : NULL))) - return malware_errlog_defer("error while creating mbox spool file"); + return malware_errlog_defer(US"error while creating mbox spool file"); /* none of our current scanners need the mbox file as a stream, so we can close it right away */ @@ -416,7 +416,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) sep = 0; /* compile the regex, see if it works */ - if (!(re = m_pcre_compile(CS malware_regex, &errstr))) + if (!(re = m_pcre_compile(malware_regex, &errstr))) return malware_errlog_defer(errstr); /* if av_scanner starts with a dollar, expand it first */ @@ -437,7 +437,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) /* find the scanner type from the av_scanner option */ if (!(scanner_name = string_nextinlist(&av_scanner_work, &sep, NULL, 0))) - return malware_errlog_defer("av_scanner configuration variable is empty"); + return malware_errlog_defer(US"av_scanner configuration variable is empty"); for (scanent = m_scans; ; scanent++) { if (!scanent->name) @@ -500,7 +500,6 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) /* v0.1 - added support for tcp sockets */ /* v0.0 - initial release -- support for unix sockets */ { - struct sockaddr_un server; int sock, result; unsigned int fsize; uschar * tmpbuf, *drweb_fbuf; @@ -616,7 +615,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) if ((bread = recv(sock, &drweb_vnum, sizeof(drweb_vnum), 0) != sizeof(drweb_vnum))) { (void)close(sock); - return drweb_errlog_defer("unable to read the number of viruses"); + return drweb_errlog_defer(US"unable to read the number of viruses"); } drweb_vnum = ntohl(drweb_vnum); @@ -625,10 +624,10 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) int i; /* setup default virus name */ - malware_name = "unknown"; + malware_name = US"unknown"; /* set up match regex */ - drweb_re = m_pcre_compile( "infected\\swith\\s*(.+?)$", &errstr); + drweb_re = m_pcre_compile(US"infected\\swith\\s*(.+?)$", &errstr); /* read and concatenate virus names into one string */ for (i=0;i 0) { /* set up match regex, depends on retcode */ kav_re = m_pcre_compile( kav_rc == 3 - ? "suspicion:\\s*(.+?)\\s*$" - : "infected:\\s*(.+?)\\s*$", + ? US"suspicion:\\s*(.+?)\\s*$" + : US"infected:\\s*(.+?)\\s*$", &errstr ); /* read report, linewise */ @@ -972,10 +968,9 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) uschar linebuffer[32767]; int trigger = 0; uschar *p; - BOOL fits; if (!cmdline_scanner) - return cmdl_errlog_defer("missing commandline specification"); + return cmdl_errlog_defer(US"missing commandline specification"); /* find scanner output trigger */ cmdline_trigger_re = m_pcre_nextinlist(&av_scanner_work, &sep, @@ -1072,7 +1067,6 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) case M_SOPHIE: /* "sophie" scanner type --------------------------------- */ { int bread = 0; - struct sockaddr_un server; int sock; uschar *p; uschar * file_name; @@ -1115,7 +1109,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) malware_name = string_copy(&av_buffer[2]); } else if (!strncmp(CS av_buffer, "-1", 2)) - return soph_errlog_defer("scanner reported error"); + return soph_errlog_defer(US"scanner reported error"); else /* all ok, no virus */ malware_name = NULL; break; @@ -1136,12 +1130,11 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) * See Exim bug 926 for details. */ uschar *p, *vname, *result_tag, *response_end; - struct sockaddr_un server; int sock, bread=0; unsigned int port; uschar * file_name; uschar av_buffer[1024]; - uschar *hostname = ""; + uschar *hostname = US""; host_item connhost; uschar *clamav_fbuf; int clam_fd, result; @@ -1186,7 +1179,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) /* extract host and port part */ if( sscanf(CS address, "%" MAX_CLAMD_ADDRESS_LENGTH_S "s %u", this_clamd->tcp_addr, &(this_clamd->tcp_port)) != 2 ) { - clmd_errlog(string_sprintf("invalid address '%s'", address)); + clmd_errlog(string_sprintf(US"invalid address '%s'", address)); continue; } @@ -1203,7 +1196,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) /* check if we have at least one server */ if (!num_servers) - return clmd_errlog_defer("no useable server addresses in malware configuration option."); + return clmd_errlog_defer(US"no useable server addresses in malware configuration option."); } /* See the discussion of response formats below to see why we really don't @@ -1230,7 +1223,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) /* Lookup the host. This is to ensure that we connect to the same IP * on both connections (as one host could resolve to multiple ips) */ - sock= m_tcpsocket(CS clamd_address_vector[current_server]->tcp_addr, + sock= m_tcpsocket(clamd_address_vector[current_server]->tcp_addr, clamd_address_vector[current_server]->tcp_port, &connhost, &errstr); if (sock >= 0) { @@ -1249,7 +1242,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) } if ( num_servers == 0 ) - return clmd_errlog_defer("all servers failed"); + return clmd_errlog_defer(US"all servers failed"); } else { if((sock = m_unixsocket(scanner_options, &errstr)) < 0) @@ -1346,7 +1339,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) CLOSE_SOCKDATA; (void)close(sock); (void)close(clam_fd); return clmd_errlog_defer( string_sprintf("can't seek spool file %s: %s", - eml_filename, strerror(errno))); + eml_filename, strerror(err))); } lseek(clam_fd, 0, SEEK_SET); @@ -1441,7 +1434,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) string_sprintf("unable to read from socket (%s)", strerror(errno))); if (bread == sizeof(av_buffer)) - return clmd_errlog_defer("buffer too small"); + return clmd_errlog_defer(US"buffer too small"); /* We're now assured of a NULL at the end of av_buffer */ /* Check the result. ClamAV returns one of two result formats. @@ -1465,7 +1458,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) passing a filename to clamd). */ if (!(*av_buffer)) - return clmd_errlog_defer("ClamAV returned null"); + return clmd_errlog_defer(US"ClamAV returned null"); /* strip newline at the end (won't be present for zINSTREAM) (also any trailing whitespace, which shouldn't exist, but we depend upon @@ -1546,10 +1539,10 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) if ((sockline_scanner = string_nextinlist(&av_scanner_work, &sep, NULL, 0))) { /* check for no expansions apart from one %s */ - char * s = index(sockline_scanner, '%'); + char * s = index(CS sockline_scanner, '%'); if (s++) - if (*s != 's' && *s != '%' || index(s+1, '%')) - return sock_errlog_defer("unsafe sock scanner call spec"); + if ((*s != 's' && *s != '%') || index(s+1, '%')) + return sock_errlog_defer(US"unsafe sock scanner call spec"); } else sockline_scanner = sockline_scanner_default; @@ -1593,7 +1586,7 @@ malware_internal(uschar **listptr, uschar *eml_filename, BOOL faking) string_sprintf("unable to read from socket (%s)", strerror(err))); if (bread == sizeof(av_buffer)) - return sock_errlog_defer("buffer too small"); + return sock_errlog_defer(US"buffer too small"); linebuffer = string_copy(av_buffer); /* try trigger match */ @@ -1685,7 +1678,7 @@ mksd_writev (int sock, struct iovec *iov, int iovcnt) while ((i < 0) && (errno == EINTR)); if (i <= 0) { close (sock); - malware_errlog("unable to write to mksd UNIX socket (/var/run/mksd/socket)"); + malware_errlog(US"unable to write to mksd UNIX socket (/var/run/mksd/socket)"); return -1; } @@ -1712,7 +1705,7 @@ mksd_read_lines (int sock, uschar *av_buffer, int av_buffer_size) do { if ((i = recv (sock, av_buffer+offset, av_buffer_size-offset, 0)) <= 0) { close (sock); - malware_errlog("unable to read from mksd UNIX socket (/var/run/mksd/socket)"); + malware_errlog(US"unable to read from mksd UNIX socket (/var/run/mksd/socket)"); return -1; } @@ -1720,7 +1713,7 @@ mksd_read_lines (int sock, uschar *av_buffer, int av_buffer_size) /* offset == av_buffer_size -> buffer full */ if (offset == av_buffer_size) { close (sock); - malware_errlog("malformed reply received from mksd"); + malware_errlog(US"malformed reply received from mksd"); return -1; } } while (av_buffer[offset-1] != '\n'); @@ -1750,7 +1743,7 @@ mksd_parse_line (char *line) if (((p-line) > 5) && (line[3] == ' ')) if (((p = strchr (line+4, ' ')) != NULL) && ((p-line) > 4)) { *p = '\0'; - malware_name = string_copy(line+4); + malware_name = string_copy(US line+4); return OK; } } -- 2.30.2