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: Tue, 15 Nov 2016 18:12:09 +0200 Message-ID: <83d1hwhgdi.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> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1479226427 13375 195.159.176.226 (15 Nov 2016 16:13:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 15 Nov 2016 16:13:47 +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 Tue Nov 15 17:13:43 2016 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 1c6gMI-0008RO-IN for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Nov 2016 17:13:18 +0100 Original-Received: from localhost ([::1]:47344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6gML-0007Ud-LS for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Nov 2016 11:13:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6gM5-0007PT-U3 for bug-gnu-emacs@gnu.org; Tue, 15 Nov 2016 11:13:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6gM2-0003HU-Ok for bug-gnu-emacs@gnu.org; Tue, 15 Nov 2016 11:13:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c6gM2-0003H9-MA for bug-gnu-emacs@gnu.org; Tue, 15 Nov 2016 11:13:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c6gM2-0002ec-FM for bug-gnu-emacs@gnu.org; Tue, 15 Nov 2016 11:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Nov 2016 16:13:02 +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.147922634110154 (code B ref 24751); Tue, 15 Nov 2016 16:13:02 +0000 Original-Received: (at 24751) by debbugs.gnu.org; 15 Nov 2016 16:12:21 +0000 Original-Received: from localhost ([127.0.0.1]:58376 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c6gLN-0002di-3I for submit@debbugs.gnu.org; Tue, 15 Nov 2016 11:12:21 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:39160) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c6gLL-0002dT-B1 for 24751@debbugs.gnu.org; Tue, 15 Nov 2016 11:12:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6gLF-0002tY-8x for 24751@debbugs.gnu.org; Tue, 15 Nov 2016 11:12:14 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:59822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6gLF-0002tR-5S; Tue, 15 Nov 2016 11:12:13 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3166 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1c6gLE-0000QF-PA; Tue, 15 Nov 2016 11:12:13 -0500 In-reply-to: <87wpg5l9st.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:125718 Archived-At: > From: npostavs@users.sourceforge.net > Cc: 24751@debbugs.gnu.org > Date: Mon, 14 Nov 2016 22:08:18 -0500 > > Actually, we should avoid increasing this limit if the stack wasn't > increased, right? Here's what I came up with, I think it doesn't cover > Cygwin/Windows though. > > diff --git c/src/emacs.c i/src/emacs.c > index b74df21..d4655c8 100644 > --- c/src/emacs.c > +++ i/src/emacs.c > @@ -831,8 +831,8 @@ main (int argc, char **argv) > re_max_failures, then add 33% to cover the size of the > smaller stacks that regex.c successively allocates and > discards on its way to the maximum. */ > - int ratio = 20 * sizeof (char *); > - ratio += ratio / 3; > + int min_ratio = 20 * sizeof (char *); > + int ratio = min_ratio + min_ratio / 3; > > /* Extra space to cover what we're likely to use for other reasons. */ > int extra = 200000; > @@ -869,6 +869,7 @@ main (int argc, char **argv) > > /* Don't let regex.c overflow the stack. */ > re_max_failures = lim < extra ? 0 : min (lim - extra, SIZE_MAX) / ratio; > + emacs_re_safe_alloca = re_max_failures * min_ratio; > } > #endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */ Right, but I have 2 comments: . we shouldn't set re_max_failures to zero if the amount of stack is less than 'extra', since in that case we will allocate the failure stack off the heap; . emacs_re_safe_alloca should have its minimum value MAX_ALLOCA, not zero, because SAFE_ALLOCA can still be used in regex.c, even though the failure stack will be malloc'ed. Thanks.