tidying: coverity issues
authorJeremy Harris <jgh146exb@wizmail.org>
Tue, 15 Mar 2016 19:39:07 +0000 (19:39 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Tue, 15 Mar 2016 19:39:07 +0000 (19:39 +0000)
src/exim_monitor/em_log.c
src/exim_monitor/em_main.c
src/exim_monitor/em_menu.c
src/src/config.h.defaults
src/src/expand.c
src/src/spool_mbox.c
src/src/spool_out.c

index 6efd9c0c96ee3157bf05a6194575332cdb1793c0..4d8c29312e28290a378979de6593618473732015 100644 (file)
@@ -217,7 +217,11 @@ uschar buffer[log_buffer_len];
 
 if (LOG != NULL)
   {
 
 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)
     {
 
   while (Ufgets(buffer, log_buffer_len, LOG) != NULL)
     {
@@ -393,7 +397,11 @@ if (LOG == NULL ||
     {
     if (LOG != NULL) fclose(LOG);
     LOG = TEST;
     {
     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;
     }
   }
     log_inode = statdata.st_ino;
     }
   }
index 69354c0862e0b88469ed546c84d5d4ef247b0490..019bdffdadb70ec15c8b8b7fe445f4d401b5f407 100644 (file)
@@ -669,8 +669,14 @@ if (log_file[0] != 0)
     {
     fseek(LOG, 0, SEEK_END);
     log_position = ftell(LOG);
     {
     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
     }
   }
 else
index af9ef37016258483e2c0ccd3a85ea6e3703a823b..6975e709dd91f9281d27f705467f800a7842a9db 100644 (file)
@@ -273,8 +273,12 @@ if (pipe(pipe_fd) != 0)
   return;
   }
 
   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
 
 /* 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;
 {
 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"");
 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;
 {
 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"");
 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;
 {
 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;
 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);
 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);
 action_required = US"-Mes";
 dialog_ref_widget = menushell;
 create_dialog(US"New sender address?", sender);
index c1cf1a9b487dc5688eb89cca4902861f492613ef..a7b505a48302c48381bc8fab551f841abdf477cf 100644 (file)
@@ -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
 /* 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 */
 #define int_eximarith_t int64_t
 #define PR_EXIM_ARITH "%" PRId64               /* C99 standard, printf %lld */
 #define SC_EXIM_ARITH "%" SCNi64               /* scanf incl. 0x prefix */
index 47f1453bebc2cf89cf906e8d1d75c698f1cfeffd..892134c0fd7720bc986c51779b099a227cd4f476 100644 (file)
@@ -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
 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
               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;
       }
 
       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:
     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;
 
        case DEFER:
           expand_string_forcedfail = TRUE;
+         /*FALLTHROUGH*/
        default:
           expand_string_message = string_sprintf("error from acl \"%s\"", sub[0]);
          return NULL;
        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);
 {
 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);
   {
   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;
     }
   }
     if (op == '+') x += y; else x -= y;
     }
   }
@@ -4049,6 +4057,7 @@ while (*s != 0)
 
        case DEFER:
           expand_string_forcedfail = TRUE;
 
        case DEFER:
           expand_string_forcedfail = TRUE;
+         /*FALLTHROUGH*/
        default:
           expand_string_message = string_sprintf("error from acl \"%s\"", sub[0]);
          goto EXPAND_FAILED;
        default:
           expand_string_message = string_sprintf("error from acl \"%s\"", sub[0]);
          goto EXPAND_FAILED;
index 12603757498444f518f3781c33c1b2981f199b64..63542ebefa53a33b1c3fc1375a0dd3ace011b075 100644 (file)
@@ -21,7 +21,7 @@ extern int malware_ok;
 extern int spam_ok;
 
 int spool_mbox_ok = 0;
 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 */
 
 /* 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;
 
   (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;
   }
 
   spool_mbox_ok = 1;
   }
 
index 62909915ffe4d68f5db5df18ad93fdd8c6988015..638190f84cc32111e00b26c5d3034b9e324d29c7 100644 (file)
@@ -272,21 +272,25 @@ fprintf(f, "%d\n", recipients_count);
 for (i = 0; i < recipients_count; i++)
   {
   recipient_item *r = recipients_list + i;
 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
     {
   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
     /* 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 */
   }
 
 /* Put a blank line before the headers */
@@ -297,7 +301,8 @@ fprintf(f, "\n");
 to get the actual size of the headers. */
 
 fflush(f);
 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
 size_correction = statbuf.st_size;
 
 /* Finally, write out the message's headers. To make it easier to read them