From 13559da6973c1cd590467eec74fda18717fe0116 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Fri, 26 Feb 2016 16:14:04 +0000 Subject: Tidying: Issues detected by gcc --fsanitize=undefined --- doc/doc-txt/ChangeLog | 5 +++++ src/src/auths/sha1.c | 8 ++++---- src/src/expand.c | 2 ++ src/src/host.c | 6 +++--- src/src/readconf.c | 1 + src/src/transports/autoreply.c | 4 ++-- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index 7f8a62546..a3911ac18 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -175,6 +175,11 @@ JH/42 Bug 1796: Fix error logged on a malware scanner connection failure. HS/04 Add support for keep_environment and add_environment options. +JH/43 Tidy coding issues detected by gcc --fsanitize=undefined. Some remain; + either intentional arithmetic overflow during PRNG, or testing config- + induced overflows. + + Exim version 4.86 ----------------- diff --git a/src/src/auths/sha1.c b/src/src/auths/sha1.c index 67a11912e..a92bb71d1 100644 --- a/src/src/auths/sha1.c +++ b/src/src/auths/sha1.c @@ -62,15 +62,15 @@ Returns: nothing void sha1_mid(sha1 *base, const uschar *text) { -register int i; -unsigned int A, B, C, D, E; -unsigned int W[80]; +int i; +uint A, B, C, D, E; +uint W[80]; base->length += 64; for (i = 0; i < 16; i++) { - W[i] = (text[0] << 24) | (text[1] << 16) | (text[2] << 8) | text[3]; + W[i] = ((uint)text[0] << 24) | (text[1] << 16) | (text[2] << 8) | text[3]; text += 4; } diff --git a/src/src/expand.c b/src/src/expand.c index 66172f378..b4cc79d4b 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1073,6 +1073,8 @@ return s; Returns: a pointer to the character after the last digit */ +/*XXX consider expanding to int_eximarith_t. But the test for +"overbig numbers" in 0002 still needs to overflow it. */ static uschar * read_number(int *n, uschar *s) diff --git a/src/src/host.c b/src/src/host.c index 90ba852d8..6a6e7abf8 100644 --- a/src/src/host.c +++ b/src/src/host.c @@ -1067,7 +1067,7 @@ if (Ustrchr(address, ':') != NULL) /* Handle IPv4 address */ (void)sscanf(CS address, "%d.%d.%d.%d", x, x+1, x+2, x+3); -bin[v4offset] = (x[0] << 24) + (x[1] << 16) + (x[2] << 8) + x[3]; +bin[v4offset] = ((uint)x[0] << 24) + (x[1] << 16) + (x[2] << 8) + x[3]; return v4offset+1; } @@ -1098,7 +1098,7 @@ for (i = 0; i < count; i++) if (mask == 0) wordmask = 0; else if (mask < 32) { - wordmask = (-1) << (32 - mask); + wordmask = (uint)(-1) << (32 - mask); mask = 0; } else @@ -1321,7 +1321,7 @@ for (i = 0; i < size; i++) if (mlen == 0) mask = 0; else if (mlen < 32) { - mask = (-1) << (32 - mlen); + mask = (uint)(-1) << (32 - mlen); mlen = 0; } else diff --git a/src/src/readconf.c b/src/src/readconf.c index ead74c1d0..3654f19d1 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -2039,6 +2039,7 @@ switch (type) /* Integer held in K: again, allow octal and hex formats, and suffixes K and M. */ + /*XXX consider moving to int_eximarith_t (but mind the overflow test 0415) */ case opt_Kint: { diff --git a/src/src/transports/autoreply.c b/src/src/transports/autoreply.c index d2aad542a..e93267e48 100644 --- a/src/src/transports/autoreply.c +++ b/src/src/transports/autoreply.c @@ -267,7 +267,6 @@ autoreply_transport_entry( { int fd, pid, rc; int cache_fd = -1; -int log_fd = -1; int cache_size = 0; int add_size = 0; EXIM_DB *dbm_file = NULL; @@ -522,9 +521,10 @@ if (oncelog != NULL && *oncelog != 0 && to != NULL) if (then != 0 && (once_repeat_sec <= 0 || now - then < once_repeat_sec)) { + int log_fd; DEBUG(D_transport) debug_printf("message previously sent to %s%s\n", to, (once_repeat_sec > 0)? " and repeat time not reached" : ""); - log_fd = Uopen(logfile, O_WRONLY|O_APPEND|O_CREAT, ob->mode); + log_fd = logfile ? Uopen(logfile, O_WRONLY|O_APPEND|O_CREAT, ob->mode) : -1; if (log_fd >= 0) { uschar *ptr = log_buffer; -- cgit v1.2.3