From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#24751: 26.0.50; Regex stack overflow not detected properly (gets "Variable binding depth exceeds max-specpdl-size") Date: Mon, 02 Jan 2017 17:24:26 +0200 Message-ID: <83r34lfpsl.fsf@gnu.org> References: <87twc6tl0i.fsf@users.sourceforge.net> <83h97nlknj.fsf@gnu.org> <87mvhdoh4q.fsf@users.sourceforge.net> <83zilcipcr.fsf@gnu.org> <87a8d4lyzo.fsf@users.sourceforge.net> <83a8d3cq9s.fsf@gnu.org> <87wpg5l9st.fsf@users.sourceforge.net> <83d1hwhgdi.fsf@gnu.org> <87r36ckzca.fsf@users.sourceforge.net> <83polvfl3h.fsf@gnu.org> <87oa1fknx9.fsf@users.sourceforge.net> <83y40idqm3.fsf@gnu.org> <877f6e6p79.fsf@users.sourceforge.net> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1483370715 28726 195.159.176.226 (2 Jan 2017 15:25:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 2 Jan 2017 15:25:15 +0000 (UTC) Cc: 24751@debbugs.gnu.org To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 02 16:25:10 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cO4U0-0006a2-Vi for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jan 2017 16:25:09 +0100 Original-Received: from localhost ([::1]:57376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cO4U3-00027u-JT for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jan 2017 10:25:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cO4Tx-00026U-4Y for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 10:25:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cO4Tt-00022M-UH for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 10:25:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52313) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cO4Tt-00022I-R4 for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 10:25:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cO4Tt-000822-MJ for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 10:25:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jan 2017 15:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24751 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24751-submit@debbugs.gnu.org id=B24751.148337067230837 (code B ref 24751); Mon, 02 Jan 2017 15:25:01 +0000 Original-Received: (at 24751) by debbugs.gnu.org; 2 Jan 2017 15:24:32 +0000 Original-Received: from localhost ([127.0.0.1]:39479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cO4TQ-00081J-CY for submit@debbugs.gnu.org; Mon, 02 Jan 2017 10:24:32 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46036) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cO4TO-000816-KJ for 24751@debbugs.gnu.org; Mon, 02 Jan 2017 10:24:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cO4TG-0001qP-7k for 24751@debbugs.gnu.org; Mon, 02 Jan 2017 10:24:25 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:39506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cO4TG-0001qL-41; Mon, 02 Jan 2017 10:24:22 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:4406 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cO4TD-0003OQ-ET; Mon, 02 Jan 2017 10:24:21 -0500 In-reply-to: <877f6e6p79.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:127674 Archived-At: > From: npostavs@users.sourceforge.net > Cc: 24751@debbugs.gnu.org > Date: Sun, 01 Jan 2017 23:49:46 -0500 > > Everything you've said makes sense after your last message, but I'm > still unable to put it together and come up with a revised comment. > Could you make a suggestion? How about the below? --- src/regex.c~0 2016-12-11 06:39:19.000000000 +0200 +++ src/regex.c 2017-01-02 12:40:44.266517100 +0200 @@ -1195,24 +1195,28 @@ gettext_noop ("Range striding over charsets") /* REG_ERANGEX */ }; -/* Avoiding alloca during matching, to placate r_alloc. */ +/* Whether to allocate memory during matching. */ -/* Define MATCH_MAY_ALLOCATE unless we need to make sure that the - searching and matching functions should not call alloca. On some - systems, alloca is implemented in terms of malloc, and if we're - using the relocating allocator routines, then malloc could cause a - relocation, which might (if the strings being searched are in the - ralloc heap) shift the data out from underneath the regexp - routines. - - Here's another reason to avoid allocation: Emacs - processes input from X in a signal handler; processing X input may - call malloc; if input arrives while a matching routine is calling - malloc, then we're scrod. But Emacs can't just block input while - calling matching routines; then we don't notice interrupts when - they come in. So, Emacs blocks input around all regexp calls - except the matching calls, which it leaves unprotected, in the - faith that they will not malloc. */ +/* Define MATCH_MAY_ALLOCATE to allow the searching and matching + functions allocate memory for the failure stack and registers. + Normally should be defined, because otherwise searching and + matching routines will have much smaller memory resources at their + disposal, and therefore might fail to handle complex regexps. + Therefore undefine MATCH_MAY_ALLOCATE only in the following + exceptional situations: + + . When running on a system where memory is at premium. + . When alloca cannot be used at all, perhaps due to bugs in + its implementation, or its being unavailable, or due to a + very small stack size. This requires to define REGEX_MALLOC + to use malloc instead, which in turn could lead to memory + leaks if search is interrupted by a signal. (For these + reasons, defining REGEX_MALLOC when building Emacs + automatically undefines MATCH_MAY_ALLOCATE, but outside + Emacs you may not care about memory leaks.) If you want to + prevent the memory leaks, undefine MATCH_MAY_ALLOCATE. + . When code that calls the searching and matching functions + cannot allow memory allocation, for whatever reasons. */ /* Normally, this is fine. */ #define MATCH_MAY_ALLOCATE