From bb07bcd32250965a896b0856dd1b839b5795e2f4 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sat, 14 Oct 2017 19:16:59 +0100 Subject: [PATCH] Tidy build for OpenBSD --- src/OS/os.h-OpenBSD | 25 ++++++++++++++++++++++++- src/src/acl.c | 2 +- src/src/buildconfig.c | 30 ++++++++++++++++++++---------- src/src/deliver.c | 20 ++++++++++---------- src/src/dkim.c | 10 +++++----- src/src/dkim_transport.c | 12 ++++++++++-- src/src/exim.c | 13 ++++++------- src/src/expand.c | 27 ++++++++++++++++----------- src/src/filter.c | 2 +- src/src/lookups/lf_sqlperform.c | 2 +- src/src/macros.h | 4 ++-- src/src/parse.c | 4 ++-- src/src/rewrite.c | 2 +- src/src/routers/rf_change_domain.c | 4 ++-- src/src/sieve.c | 1 - src/src/spool_in.c | 4 ++-- src/src/tlscert-openssl.c | 4 ++-- src/src/transport.c | 2 +- src/src/transports/appendfile.c | 4 ++-- src/src/transports/smtp_socks.c | 2 -- src/src/verify.c | 8 +++----- test/stdout/2132 | 4 ++++ 22 files changed, 115 insertions(+), 71 deletions(-) diff --git a/src/OS/os.h-OpenBSD b/src/OS/os.h-OpenBSD index 5d55a967e..9da2599c1 100644 --- a/src/OS/os.h-OpenBSD +++ b/src/OS/os.h-OpenBSD @@ -10,7 +10,7 @@ if the version released is past that point. */ #include #if OpenBSD >= 201405 -#define NOT_HAVE_ARC4RANDOM_STIR +# define NOT_HAVE_ARC4RANDOM_STIR #endif typedef struct flock flock_t; @@ -27,4 +27,27 @@ typedef struct __res_state *res_state; # define EPROTO 71 #endif +/* We need to force this; the automatic in buildconfig.c gets %ld */ +#ifdef OFF_T_FMT +# undef OFF_T_FMT +# undef LONGLONG_T +#endif +#define OFF_T_FMT "%lld" +#define LONGLONG_T long long int + +#ifdef PID_T_FMT +# undef PID_T_FMT +#endif +#define PID_T_FMT "%d" + +#ifdef INO_T_FMT +# undef INO_T_FMT +#endif +#define INO_T_FMT "%llu" + +#ifdef TIME_T_FMT +# undef TIME_T_FMT +#endif +#define TIME_T_FMT "%lld" + /* End */ diff --git a/src/src/acl.c b/src/src/acl.c index 79feb5f68..921cb2ce8 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -3931,7 +3931,7 @@ if (acl_level == 0) } else ss = s; -while (isspace(*ss))ss++; +while (isspace(*ss)) ss++; /* If we can't find a named ACL, the default is to parse it as an inline one. (Unless it begins with a slash; non-existent files give rise to an error.) */ diff --git a/src/src/buildconfig.c b/src/src/buildconfig.c index 4ed287414..591bf831d 100644 --- a/src/src/buildconfig.c +++ b/src/src/buildconfig.c @@ -101,6 +101,7 @@ main(int argc, char **argv) { off_t test_off_t = 0; time_t test_time_t = 0; +ino_t test_ino_t; #if ! (__STDC_VERSION__ >= 199901L) size_t test_size_t = 0; ssize_t test_ssize_t = 0; @@ -153,13 +154,13 @@ This assumption is known to be OK for the common operating systems. */ fprintf(new, "#ifndef OFF_T_FMT\n"); if (sizeof(test_off_t) > sizeof(test_long_t)) { - fprintf(new, "#define OFF_T_FMT \"%%lld\"\n"); - fprintf(new, "#define LONGLONG_T long long int\n"); + fprintf(new, "# define OFF_T_FMT \"%%lld\"\n"); + fprintf(new, "# define LONGLONG_T long long int\n"); } else { - fprintf(new, "#define OFF_T_FMT \"%%ld\"\n"); - fprintf(new, "#define LONGLONG_T long int\n"); + fprintf(new, "# define OFF_T_FMT \"%%ld\"\n"); + fprintf(new, "# define LONGLONG_T long int\n"); } fprintf(new, "#endif\n\n"); @@ -171,14 +172,23 @@ off_t. */ fprintf(new, "#ifndef TIME_T_FMT\n"); if (sizeof(test_time_t) > sizeof(test_long_t)) { - fprintf(new, "#define TIME_T_FMT \"%%lld\"\n"); - fprintf(new, "#undef LONGLONG_T\n"); - fprintf(new, "#define LONGLONG_T long long int\n"); + fprintf(new, "# define TIME_T_FMT \"%%lld\"\n"); + fprintf(new, "# undef LONGLONG_T\n"); + fprintf(new, "# define LONGLONG_T long long int\n"); } else - { - fprintf(new, "#define TIME_T_FMT \"%%ld\"\n"); - } + fprintf(new, "# define TIME_T_FMT \"%%ld\"\n"); +fprintf(new, "#endif\n\n"); + +fprintf(new, "#ifndef INO_T_FMT\n"); +if (sizeof(test_ino_t) > sizeof(test_long_t)) + fprintf(new, "# define INO_T_FMT \"%%llu\"\n"); +else + fprintf(new, "# define INO_T_FMT \"%%lu\"\n"); +fprintf(new, "#endif\n\n"); + +fprintf(new, "#ifndef PID_T_FMT\n"); +fprintf(new, "# define PID_T_FMT \"%%lu\"\n"); fprintf(new, "#endif\n\n"); /* And for sizeof() results, size_t, which should with C99 be just %zu, deal diff --git a/src/src/deliver.c b/src/src/deliver.c index 0bd67d823..752e1d98e 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -3314,11 +3314,11 @@ while (!done) got = readn(fd, pipeheader, required); if (got != required) { - msg = string_sprintf("got %d of %d bytes (pipeheader) " - "from transport process %d for transport %s", - got, PIPE_HEADER_SIZE, pid, addr->transport->driver_name); - done = TRUE; - break; + msg = string_sprintf("got " SSIZE_T_FMT " of %d bytes (pipeheader) " + "from transport process %d for transport %s", + got, PIPE_HEADER_SIZE, pid, addr->transport->driver_name); + done = TRUE; + break; } pipeheader[PIPE_HEADER_SIZE] = '\0'; @@ -3351,11 +3351,11 @@ while (!done) got = readn(fd, big_buffer, required); if (got != required) { - msg = string_sprintf("got only %d of %d bytes (pipedata) " - "from transport process %d for transport %s", - got, required, pid, addr->transport->driver_name); - done = TRUE; - break; + msg = string_sprintf("got only " SSIZE_T_FMT " of " SIZE_T_FMT + " bytes (pipedata) from transport process %d for transport %s", + got, required, pid, addr->transport->driver_name); + done = TRUE; + break; } /* Handle each possible type of item, assuming the complete item is diff --git a/src/src/dkim.c b/src/src/dkim.c index 723267cbf..038adb8b9 100644 --- a/src/src/dkim.c +++ b/src/src/dkim.c @@ -125,7 +125,7 @@ void dkim_exim_verify_finish(void) { pdkim_signature * sig = NULL; -int dkim_signers_size = 0, dkim_signers_ptr = 0, rc; +int rc; gstring * g = NULL; const uschar * errstr; @@ -172,7 +172,7 @@ for (sig = dkim_signatures; sig; sig = sig->next) " c=", sig->canon_headers == PDKIM_CANON_SIMPLE ? "simple" : "relaxed", "/", sig->canon_body == PDKIM_CANON_SIMPLE ? "simple" : "relaxed", " a=", dkim_sig_to_a_tag(sig), - string_sprintf(" b=%d", + string_sprintf(" b=" SIZE_T_FMT, (int)sig->sighash.len > -1 ? sig->sighash.len * 8 : 0)); if ((s= sig->identity)) logmsg = string_append(logmsg, 2, " i=", s); if (sig->created > 0) logmsg = string_cat(logmsg, @@ -340,7 +340,7 @@ switch (what) case DKIM_BODYLENGTH: return dkim_cur_sig->bodylength >= 0 - ? string_sprintf(OFF_T_FMT, (LONGLONG_T) dkim_cur_sig->bodylength) + ? string_sprintf("%ld", dkim_cur_sig->bodylength) : dkim_exim_expand_defaults(what); case DKIM_CANON_BODY: @@ -365,12 +365,12 @@ switch (what) case DKIM_CREATED: return dkim_cur_sig->created > 0 - ? string_sprintf("%llu", dkim_cur_sig->created) + ? string_sprintf("%lu", dkim_cur_sig->created) : dkim_exim_expand_defaults(what); case DKIM_EXPIRES: return dkim_cur_sig->expires > 0 - ? string_sprintf("%llu", dkim_cur_sig->expires) + ? string_sprintf("%lu", dkim_cur_sig->expires) : dkim_exim_expand_defaults(what); case DKIM_HEADERNAMES: diff --git a/src/src/dkim_transport.c b/src/src/dkim_transport.c index b61c41edc..52f87845e 100644 --- a/src/src/dkim_transport.c +++ b/src/src/dkim_transport.c @@ -37,7 +37,11 @@ return TRUE; /* Send the file at in_fd down the output fd */ static BOOL -dkt_send_file(int out_fd, int in_fd, off_t off, size_t size) +dkt_send_file(int out_fd, int in_fd, off_t off +#ifdef OS_SENDFILE + , size_t size +#endif + ) { DEBUG(D_transport) debug_printf("send file fd=%d size=%u\n", out_fd, (unsigned)(size - off)); @@ -297,7 +301,11 @@ if (options & topt_use_bdat) if(dlen > 0 && !transport_write_block(tctx, dkim_signature->s, dlen, TRUE)) goto err; -if (!dkt_send_file(tctx->u.fd, dkim_fd, 0, k_file_size)) +if (!dkt_send_file(tctx->u.fd, dkim_fd, 0 +#ifdef OS_SENDFILE + , k_file_size +#endif + )) { save_errno = errno; rc = FALSE; diff --git a/src/src/exim.c b/src/src/exim.c index 40df72c9f..e199279b8 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -4714,10 +4714,9 @@ for (i = 0;;) /* If user name has not been set by -F, set it from the passwd entry unless -f has been used to set the sender address by a trusted user. */ - if (originator_name == NULL) + if (!originator_name) { - if (sender_address == NULL || - (!trusted_caller && filter_test == FTEST_NONE)) + if (!sender_address || (!trusted_caller && filter_test == FTEST_NONE)) { uschar *name = US pw->pw_gecos; uschar *amp = Ustrchr(name, '&'); @@ -4727,11 +4726,11 @@ for (i = 0;;) replaced by a copy of the login name, and some even specify that the first character should be upper cased, so that's what we do. */ - if (amp != NULL) + if (amp) { int loffset; string_format(buffer, sizeof(buffer), "%.*s%n%s%s", - amp - name, name, &loffset, originator_login, amp + 1); + (int)(amp - name), name, &loffset, originator_login, amp + 1); buffer[loffset] = toupper(buffer[loffset]); name = buffer; } @@ -4739,7 +4738,7 @@ for (i = 0;;) /* If a pattern for matching the gecos field was supplied, apply it and then expand the name string. */ - if (gecos_pattern != NULL && gecos_name != NULL) + if (gecos_pattern && gecos_name) { const pcre *re; re = regex_must_compile(gecos_pattern, FALSE, TRUE); /* Use malloc */ @@ -4748,7 +4747,7 @@ for (i = 0;;) { uschar *new_name = expand_string(gecos_name); expand_nmax = -1; - if (new_name != NULL) + if (new_name) { DEBUG(D_receive) debug_printf("user name \"%s\" extracted from " "gecos field \"%s\"\n", new_name, name); diff --git a/src/src/expand.c b/src/src/expand.c index c2690b0c6..b146db264 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1484,14 +1484,14 @@ while (*s != 0) /* If value2 is unset, just compute one number */ if (value2 < 0) - s = string_sprintf("%d", total % value1); + s = string_sprintf("%lu", total % value1); /* Otherwise do a div/mod hash */ else { total = total % (value1 * value2); - s = string_sprintf("%d/%d", total/value2, total % value2); + s = string_sprintf("%lu/%lu", total/value2, total % value2); } *len = Ustrlen(s); @@ -3927,18 +3927,20 @@ while (*s != 0) { int len; int newsize = 0; - gstring * g; + gstring * g = NULL; s = read_name(name, sizeof(name), s, US"_"); /* If this is the first thing to be expanded, release the pre-allocated buffer. */ - if (yield && yield->ptr == 0) + if (!yield) + g = store_get(sizeof(gstring)); + else if (yield->ptr == 0) { if (resetok) store_reset(yield); yield = NULL; - g = store_get(sizeof(gstring)); + g = store_get(sizeof(gstring)); /* alloc _before_ calling find_variable() */ } /* Header */ @@ -3993,7 +3995,8 @@ while (*s != 0) yield->ptr = len; yield->s = value; } - else yield = string_catn(yield, value, len); + else + yield = string_catn(yield, value, len); continue; } @@ -7148,8 +7151,8 @@ while (*s != 0) if (error != NULL) { expand_string_message = string_sprintf("error in expression " - "evaluation: %s (after processing \"%.*s\")", error, sub-save_sub, - save_sub); + "evaluation: %s (after processing \"%.*s\")", error, + (int)(sub-save_sub), save_sub); goto EXPAND_FAILED; } sprintf(CS var_buffer, PR_EXIM_ARITH, n); @@ -7428,13 +7431,15 @@ while (*s != 0) { int len; int newsize = 0; - gstring * g; + gstring * g = NULL; - if (yield && yield->ptr == 0) + if (!yield) + g = store_get(sizeof(gstring)); + else if (yield->ptr == 0) { if (resetok) store_reset(yield); yield = NULL; - g = store_get(sizeof(gstring)); + g = store_get(sizeof(gstring)); /* alloc _before_ calling find_variable() */ } if (!(value = find_variable(name, FALSE, skipping, &newsize))) { diff --git a/src/src/filter.c b/src/src/filter.c index 0b3ef8b2d..214ae9ee6 100644 --- a/src/src/filter.c +++ b/src/src/filter.c @@ -2322,7 +2322,7 @@ while (commands != NULL) { *error_pointer = string_sprintf("Bad time value for \"once_repeat\" " "in mail or vacation command: %s", - commands->args[mailarg_index_once_repeat]); + commands->args[mailarg_index_once_repeat].u); return FF_ERROR; } } diff --git a/src/src/lookups/lf_sqlperform.c b/src/src/lookups/lf_sqlperform.c index 6d4f7a798..2084f1a21 100644 --- a/src/src/lookups/lf_sqlperform.c +++ b/src/src/lookups/lf_sqlperform.c @@ -98,7 +98,7 @@ else return DEFER; } - qserverlist = string_sprintf("%.*s", ss - s, s); + qserverlist = string_sprintf("%.*s", (int)(ss - s), s); qsep = 0; while ((qserver = string_nextinlist(&qserverlist, &qsep, qbuffer, diff --git a/src/src/macros.h b/src/src/macros.h index 82d373b11..71e8ea4bf 100644 --- a/src/src/macros.h +++ b/src/src/macros.h @@ -107,8 +107,8 @@ don't make the file descriptors two-way. */ /* Debugging control */ -#define DEBUG(x) if ((debug_selector & (x)) != 0) -#define HDEBUG(x) if (host_checking || (debug_selector & (x)) != 0) +#define DEBUG(x) if (debug_selector & (x)) +#define HDEBUG(x) if (host_checking || (debug_selector & (x))) #define PTR_CHK(ptr) \ do { \ diff --git a/src/src/parse.c b/src/src/parse.c index 68a83b0e8..1b44146c5 100644 --- a/src/src/parse.c +++ b/src/src/parse.c @@ -745,7 +745,7 @@ if (*s == '<') *errorptr = s[-1] == 0 ? US"'>' missing at end of address" : string_sprintf("malformed address: %.32s may not follow %.*s", - s-1, s - US mailbox - 1, mailbox); + s-1, (int)(s - US mailbox - 1), mailbox); goto PARSE_FAILED; } @@ -798,7 +798,7 @@ if (*s != 0) else { *errorptr = string_sprintf("malformed address: %.32s may not follow %.*s", - s, s - US mailbox, mailbox); + s, (int)(s - US mailbox), mailbox); goto PARSE_FAILED; } } diff --git a/src/src/rewrite.c b/src/src/rewrite.c index 830d2bb8d..20c9f6f18 100644 --- a/src/src/rewrite.c +++ b/src/src/rewrite.c @@ -309,7 +309,7 @@ for (rule = rewrite_rules; start = Ustrlen(pf1) + start + new - p1; end = start + Ustrlen(newparsed); - new = string_sprintf("%s%.*s%s", pf1, p2 - p1, p1, pf2); + new = string_sprintf("%s%.*s%s", pf1, (int)(p2 - p1), p1, pf2); } /* Now accept the whole thing */ diff --git a/src/src/routers/rf_change_domain.c b/src/src/routers/rf_change_domain.c index 219e283cc..4c6b28867 100644 --- a/src/src/routers/rf_change_domain.c +++ b/src/src/routers/rf_change_domain.c @@ -37,8 +37,8 @@ rf_change_domain(address_item *addr, const uschar *domain, BOOL rewrite, { address_item *parent = store_get(sizeof(address_item)); uschar *at = Ustrrchr(addr->address, '@'); -uschar *address = string_sprintf("%.*s@%s", at - addr->address, addr->address, - domain); +uschar *address = string_sprintf("%.*s@%s", + (int)(at - addr->address), addr->address, domain); DEBUG(D_route) debug_printf("domain changed to %s\n", domain); diff --git a/src/src/sieve.c b/src/src/sieve.c index 3bb10785b..29a1136ac 100644 --- a/src/src/sieve.c +++ b/src/src/sieve.c @@ -3381,7 +3381,6 @@ while (*filter->pc) { uschar *mime_body,*reason_end; static const uschar nlnl[]="\r\n\r\n"; - gstring * g; for ( diff --git a/src/src/spool_in.c b/src/src/spool_in.c index a5b14959f..8e4b96cd5 100644 --- a/src/src/spool_in.c +++ b/src/src/spool_in.c @@ -459,8 +459,8 @@ for (;;) tree_node *node; endptr = Ustrchr(big_buffer + 6, ' '); if (endptr == NULL) goto SPOOL_FORMAT_ERROR; - name = string_sprintf("%c%.*s", big_buffer[4], endptr - big_buffer - 6, - big_buffer + 6); + name = string_sprintf("%c%.*s", big_buffer[4], + (int)(endptr - big_buffer - 6), big_buffer + 6); if (sscanf(CS endptr, " %d", &count) != 1) goto SPOOL_FORMAT_ERROR; node = acl_var_create(name); node->data.ptr = store_get(count + 1); diff --git a/src/src/tlscert-openssl.c b/src/src/tlscert-openssl.c index bfd4dc112..ed8c0bba7 100644 --- a/src/src/tlscert-openssl.c +++ b/src/src/tlscert-openssl.c @@ -149,7 +149,7 @@ else time_t t = mktime(&tm); /* make the tm self-consistent */ if (mod && Ustrcmp(mod, "int") == 0) /* seconds since epoch */ - s = string_sprintf("%u", t); + s = string_sprintf(TIME_T_FMT, t); else { @@ -300,7 +300,7 @@ return mod ? tls_field_from_dn(cp, mod) : cp; uschar * tls_cert_version(void * cert, uschar * mod) { -return string_sprintf("%d", X509_get_version((X509 *)cert)); +return string_sprintf("%ld", X509_get_version((X509 *)cert)); } uschar * diff --git a/src/src/transport.c b/src/src/transport.c index 75af68f9b..89f1d74bd 100644 --- a/src/src/transport.c +++ b/src/src/transport.c @@ -588,7 +588,7 @@ at = Ustrrchr(addr->address, '@'); plen = (addr->prefix == NULL)? 0 : Ustrlen(addr->prefix); slen = Ustrlen(addr->suffix); -return string_sprintf("%.*s@%s", (at - addr->address - plen - slen), +return string_sprintf("%.*s@%s", (int)(at - addr->address - plen - slen), addr->address + plen, at + 1); } diff --git a/src/src/transports/appendfile.c b/src/src/transports/appendfile.c index 3b463c644..dc693585c 100644 --- a/src/src/transports/appendfile.c +++ b/src/src/transports/appendfile.c @@ -1980,7 +1980,7 @@ if (!isdirectory) { addr->basic_errno = ERRNO_INODECHANGED; addr->message = string_sprintf("opened mailbox %s inode number changed " - "from %d to %ld", filename, inode, statbuf.st_ino); + "from " INO_T_FMT " to " INO_T_FMT, filename, inode, statbuf.st_ino); addr->special_action = SPECIAL_FREEZE; goto RETURN; } @@ -2571,7 +2571,7 @@ else uschar *basename; (void)gettimeofday(&msg_tv, NULL); - basename = string_sprintf(TIME_T_FMT ".H%luP%lu.%s", + basename = string_sprintf(TIME_T_FMT ".H%luP" PID_T_FMT ".%s", msg_tv.tv_sec, msg_tv.tv_usec, getpid(), primary_hostname); filename = dataname = string_sprintf("tmp/%s", basename); diff --git a/src/src/transports/smtp_socks.c b/src/src/transports/smtp_socks.c index c9907dd54..dc34f001f 100644 --- a/src/src/transports/smtp_socks.c +++ b/src/src/transports/smtp_socks.c @@ -74,8 +74,6 @@ sob->priority = SOCKS_PRIORITY; static void socks_option(socks_opts * sob, const uschar * opt) { -const uschar * s; - if (Ustrncmp(opt, "auth=", 5) == 0) { opt += 5; diff --git a/src/src/verify.c b/src/src/verify.c index 922bf69e9..b957c709b 100644 --- a/src/src/verify.c +++ b/src/src/verify.c @@ -2263,7 +2263,7 @@ for (h = header_list; h != NULL && yield == OK; h = h->next) /* deconst cast ok as we're passing a non-const to string_printing() */ *msgptr = US string_printing( string_sprintf("%s: failing address in \"%.*s:\" header %s: %.*s", - errmess, tt - h->text, h->text, verb, len, s)); + errmess, (int)(tt - h->text), h->text, verb, len, s)); yield = FAIL; break; /* Out of address loop */ @@ -2564,7 +2564,7 @@ for (i = 0; i < 3 && !done; i++) while (ss > s && isspace(ss[-1])) ss--; *log_msgptr = string_sprintf("syntax error in '%.*s' header when " "scanning for sender: %s in \"%.*s\"", - endname - h->text, h->text, *log_msgptr, ss - s, s); + (int)(endname - h->text), h->text, *log_msgptr, (int)(ss - s), s); yield = FAIL; done = TRUE; break; @@ -2592,11 +2592,9 @@ for (i = 0; i < 3 && !done; i++) { *verrno = vaddr->basic_errno; if (smtp_return_error_details) - { *user_msgptr = string_sprintf("Rejected after DATA: " "could not verify \"%.*s\" header address\n%s: %s", - endname - h->text, h->text, vaddr->address, vaddr->message); - } + (int)(endname - h->text), h->text, vaddr->address, vaddr->message); } /* Success or defer */ diff --git a/test/stdout/2132 b/test/stdout/2132 index 322237463..64915c1fb 100644 --- a/test/stdout/2132 +++ b/test/stdout/2132 @@ -98,6 +98,10 @@ Connecting to ip4.ip4.ip4.ip4 port 1225 ... connected Attempting to start TLS pppp:error:dddddddd:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:[...]:SSL alert number 40 Failed to start TLS ++++ 1 +>>> help +??? 554 +<<< 554 Security failure End of script Connecting to ip4.ip4.ip4.ip4 port 1225 ... connected Certificate file = TESTSUITE/aux-fixed/exim-ca/example.com/server1.example.com/server1.example.com.pem -- 2.25.1