From 6e3b198d9efa70de98409fbb78b9f83257b2101c Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 15 Mar 2016 19:39:07 +0000 Subject: [PATCH] tidying: coverity issues --- src/exim_monitor/em_log.c | 12 ++++++++++-- src/exim_monitor/em_main.c | 10 ++++++++-- src/exim_monitor/em_menu.c | 18 +++++++++++------- src/src/config.h.defaults | 2 +- src/src/expand.c | 17 +++++++++++++---- src/src/spool_mbox.c | 4 ++-- src/src/spool_out.c | 23 ++++++++++++++--------- 7 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/exim_monitor/em_log.c b/src/exim_monitor/em_log.c index 6efd9c0c9..4d8c29312 100644 --- a/src/exim_monitor/em_log.c +++ b/src/exim_monitor/em_log.c @@ -217,7 +217,11 @@ uschar buffer[log_buffer_len]; if (LOG != NULL) { - fseek(LOG, log_position, SEEK_SET); + if (fseek(LOG, log_position, SEEK_SET)) + { + perror("logfile fseek"); + exit(1); + } while (Ufgets(buffer, log_buffer_len, LOG) != NULL) { @@ -393,7 +397,11 @@ if (LOG == NULL || { if (LOG != NULL) fclose(LOG); LOG = TEST; - fstat(fileno(LOG), &statdata); + if (fstat(fileno(LOG), &statdata)) + { + fprintf(stderr, "fstat %s: %s\n", log_file_open, strerror(errno)); + exit(1); + } log_inode = statdata.st_ino; } } diff --git a/src/exim_monitor/em_main.c b/src/exim_monitor/em_main.c index 69354c086..019bdffda 100644 --- a/src/exim_monitor/em_main.c +++ b/src/exim_monitor/em_main.c @@ -669,8 +669,14 @@ if (log_file[0] != 0) { fseek(LOG, 0, SEEK_END); log_position = ftell(LOG); - fstat(fileno(LOG), &statdata); - log_inode = statdata.st_ino; + if (fstat(fileno(LOG), &statdata)) + { + perror("log file fstat"); + fclose(LOG); + LOG=NULL; + } + else + log_inode = statdata.st_ino; } } else diff --git a/src/exim_monitor/em_menu.c b/src/exim_monitor/em_menu.c index af9ef3701..6975e709d 100644 --- a/src/exim_monitor/em_menu.c +++ b/src/exim_monitor/em_menu.c @@ -273,8 +273,12 @@ if (pipe(pipe_fd) != 0) return; } -fcntl(pipe_fd[0], F_SETFL, O_NONBLOCK); -fcntl(pipe_fd[1], F_SETFL, O_NONBLOCK); +if ( fcntl(pipe_fd[0], F_SETFL, O_NONBLOCK) + || fcntl(pipe_fd[1], F_SETFL, O_NONBLOCK)) + { + perror("set nonblocking on pipe"); + exit(1); + } /* Delivering a message can take some time, and we want to show the output as it goes along. This requires subprocesses and is coded below. For @@ -551,7 +555,7 @@ static void addrecipAction(Widget w, XtPointer client_data, XtPointer call_data) { w = w; /* Keep picky compilers happy */ call_data = call_data; -Ustrcpy(actioned_message, (uschar *)client_data); +Ustrncpy(actioned_message, client_data, 24); action_required = US"-Mar"; dialog_ref_widget = menushell; create_dialog(US"Recipient address to add?", US""); @@ -567,7 +571,7 @@ static void markdelAction(Widget w, XtPointer client_data, XtPointer call_data) { w = w; /* Keep picky compilers happy */ call_data = call_data; -Ustrcpy(actioned_message, (uschar *)client_data); +Ustrncpy(actioned_message, client_data, 24); action_required = US"-Mmd"; dialog_ref_widget = menushell; create_dialog(US"Recipient address to mark delivered?", US""); @@ -582,7 +586,7 @@ static void markalldelAction(Widget w, XtPointer client_data, XtPointer call_dat { w = w; /* Keep picky compilers happy */ call_data = call_data; -ActOnMessage((uschar *)client_data, US"-Mmad", US""); +ActOnMessage(US client_data, US"-Mmad", US""); } @@ -597,9 +601,9 @@ queue_item *q; uschar *sender; w = w; /* Keep picky compilers happy */ call_data = call_data; -Ustrcpy(actioned_message, (uschar *)client_data); +Ustrncpy(actioned_message, client_data, 24); q = find_queue(actioned_message, queue_noop, 0); -sender = (q == NULL)? US"" : (q->sender[0] == 0)? US"<>" : q->sender; +sender = !q ? US"" : q->sender[0] == 0 ? US"<>" : q->sender; action_required = US"-Mes"; dialog_ref_widget = menushell; create_dialog(US"New sender address?", sender); diff --git a/src/src/config.h.defaults b/src/src/config.h.defaults index c1cf1a9b4..a7b505a48 100644 --- a/src/src/config.h.defaults +++ b/src/src/config.h.defaults @@ -195,7 +195,7 @@ just in case. */ /* Sizes for integer arithmetic. Go for 64bit; can be overridden in OS/Makefile-FOO If you make it a different number of bits, provide a definition -for EXIM_64B_MAX and _MIN in OS/oh.h-FOO */ +for EXIM_ARITH_MAX and _MIN in OS/oh.h-FOO */ #define int_eximarith_t int64_t #define PR_EXIM_ARITH "%" PRId64 /* C99 standard, printf %lld */ #define SC_EXIM_ARITH "%" SCNi64 /* scanf incl. 0x prefix */ diff --git a/src/src/expand.c b/src/src/expand.c index 47f1453be..892134c0f 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -2058,7 +2058,7 @@ Load args from sub array to globals, and call acl_check(). Sub array will be corrupted on return. Returns: OK access is granted by an ACCEPT verb - DISCARD access is granted by a DISCARD verb + DISCARD access is (apparently) granted by a DISCARD verb FAIL access is denied FAIL_DROP access is denied; drop the connection DEFER can't tell at the moment @@ -2373,7 +2373,7 @@ switch(cond_type) case 3: return NULL; } - *resetok = FALSE; + *resetok = FALSE; /* eval_acl() might allocate; do not reclaim */ if (yield != NULL) switch(eval_acl(sub, nelem(sub), &user_msg)) { case OK: @@ -2390,6 +2390,7 @@ switch(cond_type) case DEFER: expand_string_forcedfail = TRUE; + /*FALLTHROUGH*/ default: expand_string_message = string_sprintf("error from acl \"%s\"", sub[0]); return NULL; @@ -3652,13 +3653,20 @@ eval_op_sum(uschar **sptr, BOOL decimal, uschar **error) { uschar *s = *sptr; int_eximarith_t x = eval_op_mult(&s, decimal, error); -if (*error == NULL) +if (!*error) { while (*s == '+' || *s == '-') { int op = *s++; int_eximarith_t y = eval_op_mult(&s, decimal, error); - if (*error != NULL) break; + if (*error) break; + if ( (x >= EXIM_ARITH_MAX/2 && x >= EXIM_ARITH_MAX/2) + || (x <= -(EXIM_ARITH_MAX/2) && y <= -(EXIM_ARITH_MAX/2))) + { /* over-conservative check */ + *error = op == '+' + ? US"overflow in sum" : US"overflow in difference"; + break; + } if (op == '+') x += y; else x -= y; } } @@ -4049,6 +4057,7 @@ while (*s != 0) case DEFER: expand_string_forcedfail = TRUE; + /*FALLTHROUGH*/ default: expand_string_message = string_sprintf("error from acl \"%s\"", sub[0]); goto EXPAND_FAILED; diff --git a/src/src/spool_mbox.c b/src/src/spool_mbox.c index 126037574..63542ebef 100644 --- a/src/src/spool_mbox.c +++ b/src/src/spool_mbox.c @@ -21,7 +21,7 @@ extern int malware_ok; extern int spam_ok; int spool_mbox_ok = 0; -uschar spooled_message_id[17]; +uschar spooled_message_id[MESSAGE_ID_LENGTH+1]; /* returns a pointer to the FILE, and puts the size in bytes into mbox_file_size * normally, source_file_override is NULL */ @@ -165,7 +165,7 @@ if (!spool_mbox_ok) (void)fclose(mbox_file); mbox_file = NULL; - Ustrcpy(spooled_message_id, message_id); + Ustrncpy(spooled_message_id, message_id, MESSAGE_ID_LENGTH+1); spool_mbox_ok = 1; } diff --git a/src/src/spool_out.c b/src/src/spool_out.c index 62909915f..638190f84 100644 --- a/src/src/spool_out.c +++ b/src/src/spool_out.c @@ -272,21 +272,25 @@ fprintf(f, "%d\n", recipients_count); for (i = 0; i < recipients_count; i++) { recipient_item *r = recipients_list + i; -DEBUG(D_deliver) debug_printf("DSN: Flags :%d\n", r->dsn_flags); + + DEBUG(D_deliver) debug_printf("DSN: Flags :%d\n", r->dsn_flags); + if (r->pno < 0 && r->errors_to == NULL && r->dsn_flags == 0) fprintf(f, "%s\n", r->address); else { - uschar *errors_to = (r->errors_to == NULL)? US"" : r->errors_to; + uschar * errors_to = r->errors_to ? r->errors_to : US""; /* for DSN SUPPORT extend exim 4 spool in a compatible way by - adding new values upfront and add flag 0x02 */ - uschar *orcpt = (r->orcpt == NULL)? US"" : r->orcpt; - fprintf(f, "%s %s %d,%d %s %d,%d#3\n", r->address, orcpt, Ustrlen(orcpt), r->dsn_flags, - errors_to, Ustrlen(errors_to), r->pno); + adding new values upfront and add flag 0x02 */ + uschar * orcpt = r->orcpt ? r->orcpt : US""; + + fprintf(f, "%s %s %d,%d %s %d,%d#3\n", r->address, orcpt, Ustrlen(orcpt), + r->dsn_flags, errors_to, Ustrlen(errors_to), r->pno); } - DEBUG(D_deliver) debug_printf("DSN: **** SPOOL_OUT - address: |%s| errorsto: |%s| orcpt: |%s| dsn_flags: %d\n", - r->address, r->errors_to, r->orcpt, r->dsn_flags); + DEBUG(D_deliver) debug_printf("DSN: **** SPOOL_OUT - " + "address: |%s| errorsto: |%s| orcpt: |%s| dsn_flags: %d\n", + r->address, r->errors_to, r->orcpt, r->dsn_flags); } /* Put a blank line before the headers */ @@ -297,7 +301,8 @@ fprintf(f, "\n"); to get the actual size of the headers. */ fflush(f); -fstat(fd, &statbuf); +if (fstat(fd, &statbuf)) + return spool_write_error(where, errmsg, US"fstat", temp_name, f); size_correction = statbuf.st_size; /* Finally, write out the message's headers. To make it easier to read them -- 2.30.2