emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 86d2169: Avoid ridiculously high stack limit requ


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-26 86d2169: Avoid ridiculously high stack limit requests on macOS
Date: Thu, 4 Oct 2018 12:14:42 -0400 (EDT)

branch: emacs-26
commit 86d2169ac3458412a084c7fc4047c3a389924cad
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Avoid ridiculously high stack limit requests on macOS
    
    * src/emacs.c (main): Avoid wraparound in subtraction of
    rlim_t values, in case rlim_t is an unsigned type.  (Bug#32338)
---
 src/emacs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/emacs.c b/src/emacs.c
index 483e848..f80047e 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -875,7 +875,8 @@ main (int argc, char **argv)
            newlim = rlim.rlim_max;
          newlim -= newlim % pagesize;
 
-         if (pagesize <= newlim - lim)
+         if (newlim > lim      /* in case rlim_t is an unsigned type */
+             && pagesize <= newlim - lim)
            {
              rlim.rlim_cur = newlim;
              if (setrlimit (RLIMIT_STACK, &rlim) == 0)
@@ -884,9 +885,10 @@ main (int argc, char **argv)
        }
       /* If the stack is big enough, let regex.c more of it before
          falling back to heap allocation.  */
-      emacs_re_safe_alloca = max
-        (min (lim - extra, SIZE_MAX) * (min_ratio / ratio),
-         MAX_ALLOCA);
+      if (lim < extra)
+       lim = extra;    /* avoid wrap-around in unsigned subtraction */
+      emacs_re_safe_alloca =
+       max (min (lim - extra, SIZE_MAX) * (min_ratio / ratio), MAX_ALLOCA);
     }
 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]