From 37f3dc43fb3a9e1513f8a31c49401b121c1adeb5 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sat, 12 Mar 2016 21:01:26 +0000 Subject: [PATCH] tidying: coverity issues --- src/src/functions.h | 1 + src/src/log.c | 72 ++++++++++++++++++++++++++++++++++- src/src/macros.h | 5 ++- src/src/pdkim/pdkim.c | 5 +-- src/src/receive.c | 4 +- src/src/routers/manualroute.c | 2 +- src/src/transports/smtp.c | 10 ++--- test/stderr/0557 | 2 +- test/stdout/0557 | 2 +- 9 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/src/functions.h b/src/src/functions.h index a5278a620..878ae42a7 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -170,6 +170,7 @@ extern BOOL enq_start(uschar *, unsigned); extern uschar *event_raise(uschar *, const uschar *, uschar *); extern void msg_event_raise(const uschar *, const address_item *); #endif +extern const uschar * exim_errstr(int); extern void exim_exit(int); extern void exim_nullstd(void); extern void exim_setugid(uid_t, gid_t, BOOL, uschar *); diff --git a/src/src/log.c b/src/src/log.c index 558c000d7..ccb7f3663 100644 --- a/src/src/log.c +++ b/src/src/log.c @@ -48,7 +48,77 @@ static int logging_mode = LOG_MODE_FILE; static uschar *file_path = US""; - +/* These should be kept in-step with the private delivery error +number definitions in macros.h */ + +static const uschar * exim_errstrings[] = { + US"", + US"unknown error", + US"user slash", + US"exist race", + US"not regular", + US"not directory", + US"bad ugid", + US"bad mode", + US"inode changed", + US"lock failed", + US"bad address2", + US"forbid pipe", + US"forbid file", + US"forbid reply", + US"missing pipe", + US"missing file", + US"missing reply", + US"bad redirect", + US"smtp closed", + US"smtp format", + US"spool format", + US"not absolute", + US"Exim-imposed quota", + US"held", + US"Delivery filter process failure", + US"Delivery add/remove header failure", + US"Delivery write incomplete error", + US"Some expansion failed", + US"Failed to get gid", + US"Failed to get uid", + US"Unset or non-existent transport", + US"MBX length mismatch", + US"Lookup failed routing or in smtp tpt", + US"Can't match format in appendfile", + US"Creation outside home in appendfile", + US"Can't check a list; lookup defer", + US"DNS lookup defer", + US"Failed to start TLS session", + US"Mandatory TLS session not started", + US"Failed to chown a file", + US"Failed to create a pipe", + US"When verifying", + US"When required by client", + US"Used internally in smtp transport", + US"RCPT gave 4xx error", + US"MAIL gave 4xx error", + US"DATA gave 4xx error", + US"Negotiation failed for proxy configured host", + US"Authenticator 'other' failure", + US"target not supporting SMTPUTF8", + US"", + + US"Not time for routing", + US"Not time for local delivery", + US"Not time for any remote host", + US"Local-only delivery", + US"Domain in queue_domains", + US"Transport concurrency limit", +}; + + +/************************************************/ +const uschar * +exim_errstr(int err) +{ +return errno < 0 ? exim_errstrings[-err] : CUS strerror(err); +} /************************************************* * Write to syslog * diff --git a/src/src/macros.h b/src/src/macros.h index 66abffa37..3f036e7ae 100644 --- a/src/src/macros.h +++ b/src/src/macros.h @@ -482,7 +482,8 @@ enum { #define LOGGING(opt) BIT_TEST(log_selector, log_selector_size, Li_##opt) /* Private error numbers for delivery failures, set negative so as not -to conflict with system errno values. */ +to conflict with system errno values. Take care to maintain the string +table exim_errstrings[] in log.c */ #define ERRNO_UNKNOWNERROR (-1) #define ERRNO_USERSLASH (-2) @@ -547,6 +548,8 @@ to conflict with system errno values. */ #define ERRNO_QUEUE_DOMAIN (-55) /* Domain in queue_domains */ #define ERRNO_TRETRY (-56) /* Transport concurrency limit */ + + /* Special actions to take after failure or deferment. */ enum { diff --git a/src/src/pdkim/pdkim.c b/src/src/pdkim/pdkim.c index 3aac759eb..fb2742c18 100644 --- a/src/src/pdkim/pdkim.c +++ b/src/src/pdkim/pdkim.c @@ -760,9 +760,8 @@ if (!(sig->domain && (*(sig->domain) != '\0') && *q = '\0'; /* Chomp raw header. The final newline must not be added to the signature. */ -q--; -while (q > sig->rawsig_no_b_val && (*q == '\r' || *q == '\n')) - *q = '\0'; q--; /*XXX questionable code layout; possible bug */ +while (--q > sig->rawsig_no_b_val && (*q == '\r' || *q == '\n')) + *q = '\0'; DEBUG(D_acl) { diff --git a/src/src/receive.c b/src/src/receive.c index f047392b7..6b69bcb2a 100644 --- a/src/src/receive.c +++ b/src/src/receive.c @@ -961,10 +961,12 @@ if (error_handling == ERRORS_SENDER) error_block eblock; eblock.next = NULL; eblock.text1 = text1; + eblock.text2 = US""; if (!moan_to_sender(errcode, &eblock, hptr, f, FALSE)) error_rc = EXIT_FAILURE; } -else fprintf(stderr, "exim: %s%s\n", text2, text1); /* Sic */ +else + fprintf(stderr, "exim: %s%s\n", text2, text1); /* Sic */ (void)fclose(f); exim_exit(error_rc); } diff --git a/src/src/routers/manualroute.c b/src/src/routers/manualroute.c index 46177df43..fd331b691 100644 --- a/src/src/routers/manualroute.c +++ b/src/src/routers/manualroute.c @@ -415,7 +415,7 @@ if (hostlist[0] == 0) { if (verify != v_none) goto ROUTED; addr->message = string_sprintf("error in %s router: no host(s) specified " - "for domain %s", rblock->name, domain); + "for domain %s", rblock->name, addr->domain); log_write(0, LOG_MAIN, "%s", addr->message); return DEFER; } diff --git a/src/src/transports/smtp.c b/src/src/transports/smtp.c index 135069d0f..7b340e21b 100644 --- a/src/src/transports/smtp.c +++ b/src/src/transports/smtp.c @@ -668,17 +668,17 @@ if (addr->message) } else { - log_write(0, LOG_MAIN, "%s %s", message, strerror(addr->basic_errno)); - deliver_msglog("%s %s %s\n", tod_stamp(tod_log), message, - strerror(addr->basic_errno)); + const uschar * s = exim_errstr(addr->basic_errno); + log_write(0, LOG_MAIN, "%s %s", message, s); + deliver_msglog("%s %s %s\n", tod_stamp(tod_log), message, s); } } static void msglog_line(host_item * host, uschar * message) { - deliver_msglog("%s H=%s [%s] %s\n", tod_stamp(tod_log), - host->name, host->address, message); +deliver_msglog("%s H=%s [%s] %s\n", tod_stamp(tod_log), + host->name, host->address, message); } diff --git a/test/stderr/0557 b/test/stderr/0557 index 8e5906ca8..19fd8c29f 100644 --- a/test/stderr/0557 +++ b/test/stderr/0557 @@ -1,2 +1,2 @@ LOG: MAIN - error in r1 router: no host(s) specified for domain * + error in r1 router: no host(s) specified for domain test.ex diff --git a/test/stdout/0557 b/test/stdout/0557 index 6a6bde9a4..63e22524b 100644 --- a/test/stdout/0557 +++ b/test/stdout/0557 @@ -1,4 +1,4 @@ -userx@test.ex cannot be resolved at this time: error in r1 router: no host(s) specified for domain * +userx@test.ex cannot be resolved at this time: error in r1 router: no host(s) specified for domain test.ex userx@test.ex cannot be resolved at this time: lookup failed for all hosts in r1 router: host_find_failed=ignore host_all_ignored=defer userx@test.ex cannot be resolved at this time: lookup failed for all hosts in r1 router: host_find_failed=ignore host_all_ignored=defer userx@test.ex -- 2.25.1