emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 9a19f26 1/2: Fix computation of regex stack limit


From: Noam Postavsky
Subject: [Emacs-diffs] master 9a19f26 1/2: Fix computation of regex stack limit
Date: Sun, 8 Jan 2017 23:47:53 +0000 (UTC)

branch: master
commit 9a19f26cd796c7321f659a8dbea5296b0eeea51d
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Fix computation of regex stack limit
    
    The regex stack limit was being computed as the number of stack entries,
    whereas it was being compared with the current size as measured in
    bytes.  This could cause indefinite looping when nearing the stack limit
    if re_max_failures happened not to be a multiple of sizeof
    fail_stack_elt_t (Bug #24751).
    
    * src/regex.c (GROW_FAIL_STACK): Compute both current stack size and
    limit as numbers of stack entries.
---
 src/regex.c |   15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/regex.c b/src/regex.c
index 7e70c49..8aa5433 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -1320,23 +1320,20 @@ typedef struct
 #define FAIL_STACK_GROWTH_FACTOR 4
 
 #define GROW_FAIL_STACK(fail_stack)                                    \
-  (((fail_stack).size * sizeof (fail_stack_elt_t)                      \
-    >= re_max_failures * TYPICAL_FAILURE_SIZE)                         \
+  (((fail_stack).size >= re_max_failures * TYPICAL_FAILURE_SIZE)        \
    ? 0                                                                 \
    : ((fail_stack).stack                                               \
       = REGEX_REALLOCATE_STACK ((fail_stack).stack,                    \
          (fail_stack).size * sizeof (fail_stack_elt_t),                \
-         min (re_max_failures * TYPICAL_FAILURE_SIZE,                  \
-              ((fail_stack).size * sizeof (fail_stack_elt_t)           \
-               * FAIL_STACK_GROWTH_FACTOR))),                          \
+          min (re_max_failures * TYPICAL_FAILURE_SIZE,                  \
+               ((fail_stack).size * FAIL_STACK_GROWTH_FACTOR))          \
+          * sizeof (fail_stack_elt_t)),                                 \
                                                                        \
       (fail_stack).stack == NULL                                       \
       ? 0                                                              \
       : ((fail_stack).size                                             \
-        = (min (re_max_failures * TYPICAL_FAILURE_SIZE,                \
-                ((fail_stack).size * sizeof (fail_stack_elt_t)         \
-                 * FAIL_STACK_GROWTH_FACTOR))                          \
-           / sizeof (fail_stack_elt_t)),                               \
+         = (min (re_max_failures * TYPICAL_FAILURE_SIZE,                \
+                 ((fail_stack).size * FAIL_STACK_GROWTH_FACTOR))),      \
         1)))
 
 



reply via email to

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