From 1b343d685767c01a6d621788eb88dba3ca94341b Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Fri, 6 Jun 1997 07:00:53 +0000 Subject: [PATCH] Change regular-expression primitives to treat failure-stack overflow as equivalent to "no match". Also, increase the maximum size of the failure stack from 1000 to 20000. This is important because it is far too easy to overflow the stack, the stack-overflow errors cause Edwin to bomb out. This is a problem because stack-overflow errors can be caused by user data -- the proximate example being a News message that bombed out the News reader because it had a header line was too complicated to match. Better to fail in these situations than to error. --- v7/src/microcode/rgxprim.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/v7/src/microcode/rgxprim.c b/v7/src/microcode/rgxprim.c index 4b05c28b4..fb86e7a15 100644 --- a/v7/src/microcode/rgxprim.c +++ b/v7/src/microcode/rgxprim.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: rgxprim.c,v 1.11 1997/01/02 05:21:41 cph Exp $ +$Id: rgxprim.c,v 1.12 1997/06/06 07:00:53 cph Exp $ Copyright (c) 1987-97 Massachusetts Institute of Technology @@ -39,6 +39,8 @@ MIT in each case. */ #include "edwin.h" #include "syntax.h" #include "regex.h" + +extern int re_max_failures; #define RE_CHAR_SET_P(object) \ ((STRING_P (object)) && \ @@ -84,7 +86,7 @@ MIT in each case. */ } \ PRIMITIVE_RETURN (long_to_integer (result)); \ } \ - else if ((result) == (-1)) \ + else if (((result) == (-1)) || ((result) == (-4))) \ PRIMITIVE_RETURN (SHARP_F); \ else if ((result) == (-2)) \ error_bad_range_arg (1); \ @@ -161,6 +163,7 @@ DEFINE_PRIMITIVE ("RE-COMPILE-FASTMAP", Prim_re_compile_fastmap, 4, 4, 0) text_end = (STRING_LENGTH (ARG_REF (5))); \ if (match_end > text_end) error_bad_range_arg (7); \ if (match_start > match_end) error_bad_range_arg (6); \ + re_max_failures = 20000; \ re_buffer_initialize \ ((& buffer), (STRING_LOC ((ARG_REF (2)), 0)), (ARG_REF (3)), \ text, 0, text_end, text_end, text_end); \ @@ -216,6 +219,7 @@ DEFINE_PRIMITIVE ("RE-SEARCH-SUBSTRING-BACKWARD", Prim_re_search_substr_backward if (match_start > match_end) error_bad_range_arg (6); \ if (match_end > text_end) error_bad_range_arg (7); \ if (match_start < text_start) error_bad_range_arg (6); \ + re_max_failures = 20000; \ re_buffer_initialize \ ((& buffer), (STRING_LOC ((ARG_REF (2)), 0)), (ARG_REF (3)), \ text, text_start, text_end, gap_start, (GROUP_GAP_END (group))); \ -- 2.25.1