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: Thu, 17 Nov 2016 18:21:24 +0200 Message-ID: <83y40idqm3.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> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1479399741 1674 195.159.176.226 (17 Nov 2016 16:22:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 17 Nov 2016 16:22:21 +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 Thu Nov 17 17:22:17 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 1c7PS3-0007pN-TA for geb-bug-gnu-emacs@m.gmane.org; Thu, 17 Nov 2016 17:22:16 +0100 Original-Received: from localhost ([::1]:60050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7PS7-0007ar-4N for geb-bug-gnu-emacs@m.gmane.org; Thu, 17 Nov 2016 11:22:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7PRt-0007Y4-MD for bug-gnu-emacs@gnu.org; Thu, 17 Nov 2016 11:22:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7PRq-0005OE-FZ for bug-gnu-emacs@gnu.org; Thu, 17 Nov 2016 11:22:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45459) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c7PRq-0005Nu-Cr for bug-gnu-emacs@gnu.org; Thu, 17 Nov 2016 11:22:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c7PRq-00063p-4X for bug-gnu-emacs@gnu.org; Thu, 17 Nov 2016 11:22: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: Thu, 17 Nov 2016 16:22: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.147939969323259 (code B ref 24751); Thu, 17 Nov 2016 16:22:02 +0000 Original-Received: (at 24751) by debbugs.gnu.org; 17 Nov 2016 16:21:33 +0000 Original-Received: from localhost ([127.0.0.1]:60858 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c7PRN-000635-78 for submit@debbugs.gnu.org; Thu, 17 Nov 2016 11:21:33 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:45221) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c7PRL-00062r-CG for 24751@debbugs.gnu.org; Thu, 17 Nov 2016 11:21:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7PRD-00052U-3e for 24751@debbugs.gnu.org; Thu, 17 Nov 2016 11:21:26 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7PRD-00052N-0E; Thu, 17 Nov 2016 11:21:23 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1514 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1c7PRC-0000yJ-AQ; Thu, 17 Nov 2016 11:21:22 -0500 In-reply-to: <87oa1fknx9.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:125789 Archived-At: > From: npostavs@users.sourceforge.net > Cc: 24751@debbugs.gnu.org > Date: Wed, 16 Nov 2016 18:25:22 -0500 > > One more question, is this comment (around line 1198) now obsolete? (if > not, it sounds like we might still have some serious problems) > > /* 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. */ The second part is obsolete: we no longer do anything significant from a signal handler, we just set a flag. The first part is not obsolete, but its reasoning is backwards: SAFE_ALLOCA indeed can call malloc, but it could only cause relocation if REGEX_MALLOC is defined (and ralloc.c is compiled in). And when you define REGEX_MALLOC, MATCH_MAY_ALLOCATE is undefined. So the text there should be revised. > Also this one (around line 430) > > /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we > use `alloca' instead of `malloc'. This is because using malloc in > re_search* or re_match* could cause memory leaks when C-g is used in > Emacs; also, malloc is slower and causes storage fragmentation. On > the other hand, malloc is more portable, and easier to debug. > > Because we sometimes use alloca, some routines have to be macros, > not functions -- `alloca'-allocated space disappears at the end of the > function it is called in. */ This is correct AFAIU, but perhaps it's worth adding that even if SAFE_ALLOCA decides to call malloc, it takes care to set up unwind-protect scheme that will free the allocated memory upon C-g (or any other throw-type op), and avoid leaking memory. Thanks.