]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Do not page-align mmap length. #25399
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Fri, 2 Mar 2018 14:50:21 +0000 (09:50 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 22 Mar 2018 12:47:37 +0000 (08:47 -0400)
changes/bug25399 [new file with mode: 0644]
configure.ac
src/common/compat.c
src/common/compat.h

diff --git a/changes/bug25399 b/changes/bug25399
new file mode 100644 (file)
index 0000000..290ebf4
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes (portability):
+    - Do not align mmap length, as it is not required by POSIX, and the
+      getpagesize function is deprecated. Fixes bug 25399.
index 22c8a561372cd25eb8c211da0910e28459318748..d05fdcbf3d970df522a6b3000b73a697f35921af 100644 (file)
@@ -553,6 +553,7 @@ AC_CHECK_FUNCS(
        mach_approximate_time \
         memmem \
         memset_s \
+        mmap \
        pipe \
        pipe2 \
         prctl \
@@ -1739,14 +1740,6 @@ AC_CHECK_DECLS([mlockall], , , [
 #include <sys/mman.h>
 #endif])
 
-# Some MinGW environments don't have getpagesize in unistd.h. We don't use
-# AC_CHECK_FUNCS(getpagesize), because other environments rename getpagesize
-# using macros
-AC_CHECK_DECLS([getpagesize], , , [
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif])
-
 # Allow user to specify an alternate syslog facility
 AC_ARG_WITH(syslog-facility,
 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
index e8916c8d1f2b11c12e37256588a7425ac0a2f1b9..99a7b8c0c141c5de7b96081ba45d1c559c21ac64 100644 (file)
@@ -115,7 +115,7 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
 #endif
-#ifdef HAVE_SYS_MMAN_H
+#ifdef HAVE_MMAP
 #include <sys/mman.h>
 #endif
 #ifdef HAVE_SYS_SYSLIMITS_H
@@ -203,25 +203,17 @@ tor_rename(const char *path_old, const char *path_new)
                 sandbox_intern_string(path_new));
 }
 
-/* Some MinGW builds have sys/mman.h, but not the corresponding symbols.
- * Other configs rename the symbols using macros (including getpagesize).
- * So check for sys/mman.h and unistd.h, and a getpagesize declaration. */
-#if (defined(HAVE_SYS_MMAN_H) && defined(HAVE_UNISTD_H) && \
-     defined(HAVE_DECL_GETPAGESIZE))
-#define COMPAT_HAS_MMAN_AND_PAGESIZE
-#endif
-
-#if defined(COMPAT_HAS_MMAN_AND_PAGESIZE) || \
-  defined(RUNNING_DOXYGEN)
+#if defined(HAVE_MMAP) || defined(RUNNING_DOXYGEN)
 /** Try to create a memory mapping for <b>filename</b> and return it.  On
- * failure, return NULL.  Sets errno properly, using ERANGE to mean
- * "empty file". */
+ * failure, return NULL. Sets errno properly, using ERANGE to mean
+ * "empty file". Must only be called on trusted Tor-owned files, as changing
+ * the underlying file's size causes unspecified behavior. */
 tor_mmap_t *
 tor_mmap_file(const char *filename)
 {
   int fd; /* router file */
   char *string;
-  int page_size, result;
+  int result;
   tor_mmap_t *res;
   size_t size, filesize;
   struct stat st;
@@ -250,13 +242,6 @@ tor_mmap_file(const char *filename)
     return NULL;
   }
   size = filesize = (size_t)(st.st_size);
-  /*
-   * Should we check for weird crap like mmapping a named pipe here,
-   * or just wait for if (!size) below to fail?
-   */
-  /* ensure page alignment */
-  page_size = getpagesize();
-  size += (size%page_size) ? page_size-(size%page_size) : 0;
 
   if (st.st_size > SSIZE_T_CEILING || (off_t)size < st.st_size) {
     log_warn(LD_FS, "File \"%s\" is too large. Ignoring.",filename);
index f7932c914a110d85bf6fd6d4d369721e47ac683f..1bdff8db3dce95dc2255e33ae37b05696ad93af0 100644 (file)
@@ -318,12 +318,12 @@ typedef struct tor_mmap_t {
   size_t size; /**< Size of the file. */
 
   /* None of the fields below should be accessed from outside compat.c */
-#ifdef HAVE_SYS_MMAN_H
+#ifdef HAVE_MMAP
   size_t mapping_size; /**< Size of the actual mapping. (This is this file
                         * size, rounded up to the nearest page.) */
 #elif defined _WIN32
   HANDLE mmap_handle;
-#endif /* defined(HAVE_SYS_MMAN_H) || ... */
+#endif /* defined(HAVE_MMAP) || ... */
 
 } tor_mmap_t;