Give error if overflow in quota setting in appendfile on a 32-bit
[exim.git] / src / src / transports / appendfile.c
index a2b7cfcb6fd370df5b56611b97a7da2254045d9a..bb5d90bcb6b182be46d28882ef98f859dd3a3588 100644 (file)
@@ -1,10 +1,10 @@
-/* $Cambridge: exim/src/src/transports/appendfile.c,v 1.9 2005/06/22 15:44:38 ph10 Exp $ */
+/* $Cambridge: exim/src/src/transports/appendfile.c,v 1.12 2006/02/10 16:29:20 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2005 */
+/* Copyright (c) University of Cambridge 1995 - 2006 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -271,6 +271,7 @@ mailbox_filecount */
 for (i = 0; i < 5; i++)
   {
   double d;
+  uschar *which = NULL;
 
   if (q == NULL) d = default_value; else
     {
@@ -316,33 +317,49 @@ for (i = 0; i < 5; i++)
       }
     }
 
+  /* Set each value, checking for possible overflow. */
+
   switch (i)
     {
     case 0:
+    if (d >= 2.0*1024.0*1024.0*1024.0 && sizeof(off_t) <= 4) which = US"quota";
     ob->quota_value = (off_t)d;
     q = ob->quota_filecount;
     break;
 
     case 1:
+    if (d >= 2.0*1024.0*1024.0*1024.0) which = US"quota_filecount";
     ob->quota_filecount_value = (int)d;
     q = ob->quota_warn_threshold;
     break;
 
     case 2:
+    if (d >= 2.0*1024.0*1024.0*1024.0 && sizeof(off_t) <= 4)
+      which = US"quota_warn_threshold";
     ob->quota_warn_threshold_value = (off_t)d;
     q = ob->mailbox_size_string;
     default_value = -1.0;
     break;
 
     case 3:
+    if (d >= 2.0*1024.0*1024.0*1024.0 && sizeof(off_t) <= 4)
+      which = US"mailbox_size";;
     ob->mailbox_size_value = (off_t)d;
     q = ob->mailbox_filecount_string;
     break;
 
     case 4:
+    if (d >= 2.0*1024.0*1024.0*1024.0) which = US"mailbox_filecount";
     ob->mailbox_filecount_value = (int)d;
     break;
     }
+
+  if (which != NULL)
+    {
+    *errmsg = string_sprintf("%s value %.10g is too large (overflow) in "
+      "%s transport", which, d, tblock->name);
+    return FAIL;
+    }
   }
 
 return OK;
@@ -602,7 +619,7 @@ for (h = &host; h != NULL; h = h->next)
 
   (void)ip_connect(sock, host_af, h->address, ntohs(sp->s_port), 0);
   rc = send(sock, buffer, Ustrlen(buffer) + 1, 0);
-  close(sock);
+  (void)close(sock);
 
   if (rc >= 0) break;
   DEBUG(D_transport)
@@ -1430,7 +1447,7 @@ if (!isdirectory)
     if (cfd >= 0)
       {
       transport_instance *tt = check_file_format(cfd, tblock, addr);
-      close(cfd);
+      (void)close(cfd);
 
       /* If another transport is indicated, call it and return; if no transport
       was found, just return - the error data will have been set up.*/
@@ -1622,7 +1639,7 @@ if (!isdirectory)
       sufficiently worried. */
 
       if ((rc = Ulink(hitchname, lockname)) != 0) fstat(hd, &statbuf);
-      close(hd);
+      (void)close(hd);
       Uunlink(hitchname);
       if (rc != 0 && statbuf.st_nlink != 2)
         {
@@ -2023,7 +2040,7 @@ if (!isdirectory)
 
         DEBUG(D_transport) debug_printf("failed to lock %s: %s\n", mbx_lockname,
           strerror(errno));
-        close(mbx_lockfd);
+        (void)close(mbx_lockfd);
         mbx_lockfd = -1;
         }
       else
@@ -2039,7 +2056,7 @@ if (!isdirectory)
     DEBUG(D_transport)
       debug_printf("fcntl(), flock(), or MBX locking failed - retrying\n");
 
-    close(fd);
+    (void)close(fd);
     fd = -1;
     use_lstat = TRUE;             /* Reset to use lstat first */
 
@@ -2468,7 +2485,7 @@ else
       addr->transport_return = PANIC;
       addr->message = string_sprintf("fdopen of %s ("
         "for %s transport) failed", filename, tblock->name);
-      close(fd);
+      (void)close(fd);
       Uunlink(filename);
       return FALSE;
       }
@@ -2486,7 +2503,7 @@ else
           addr->message = string_sprintf("Expansion of \"%s\" (mailstore "
             "prefix for %s transport) failed: %s", ob->mailstore_prefix,
             tblock->name, expand_string_message);
-          fclose(env_file);
+          (void)fclose(env_file);
           Uunlink(filename);
           return FALSE;
           }
@@ -2515,7 +2532,7 @@ else
           addr->message = string_sprintf("Expansion of \"%s\" (mailstore "
             "suffix for %s transport) failed: %s", ob->mailstore_suffix,
             tblock->name, expand_string_message);
-          fclose(env_file);
+          (void)fclose(env_file);
           Uunlink(filename);
           return FALSE;
           }
@@ -2732,7 +2749,7 @@ if (temp_file != NULL && ob->mbx_format)
   /* Preserve errno while closing the temporary file. */
 
   mbx_save_errno = errno;
-  fclose(temp_file);
+  (void)fclose(temp_file);
   errno = mbx_save_errno;
   }
 #endif  /* SUPPORT_MBX */
@@ -2755,7 +2772,7 @@ if (yield == OK && maildirsize_fd >= 0)
   maildir_record_length(maildirsize_fd, message_size);
 
 maildir_save_errno = errno;       /* Preserve errno while closing the file */
-close(maildirsize_fd);
+(void)close(maildirsize_fd);
 errno = maildir_save_errno;
 #endif  /* SUPPORT_MAILDIR */
 
@@ -3130,7 +3147,7 @@ if (mbx_lockfd >= 0)
       debug_printf("unlinking MBX lock file %s\n", mbx_lockname);
     Uunlink(mbx_lockname);
     }
-  close(mbx_lockfd);
+  (void)close(mbx_lockfd);
   }
 #endif  /* SUPPORT_MBX */