From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.bugs Subject: bug#18410: Use SAFE_ALLOCA etc. to avoid unbounded stack allocation. Date: Fri, 05 Sep 2014 12:45:27 +0400 Message-ID: <54097827.1020508@yandex.ru> References: <5409536B.5090201@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1409907635 10919 80.91.229.3 (5 Sep 2014 09:00:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Sep 2014 09:00:35 +0000 (UTC) Cc: 18410@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 05 11:00:27 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XPpNQ-000056-S6 for geb-bug-gnu-emacs@m.gmane.org; Fri, 05 Sep 2014 11:00:16 +0200 Original-Received: from localhost ([::1]:56425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPpNQ-0005BH-JD for geb-bug-gnu-emacs@m.gmane.org; Fri, 05 Sep 2014 05:00:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPp9m-0000bs-53 for bug-gnu-emacs@gnu.org; Fri, 05 Sep 2014 04:46:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPp9f-0006Vl-2c for bug-gnu-emacs@gnu.org; Fri, 05 Sep 2014 04:46:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPp9e-0006Va-GH for bug-gnu-emacs@gnu.org; Fri, 05 Sep 2014 04:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XPp9e-0004o5-0e for bug-gnu-emacs@gnu.org; Fri, 05 Sep 2014 04:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Antipov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 05 Sep 2014 08:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18410 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18410-submit@debbugs.gnu.org id=B18410.140990674418440 (code B ref 18410); Fri, 05 Sep 2014 08:46:01 +0000 Original-Received: (at 18410) by debbugs.gnu.org; 5 Sep 2014 08:45:44 +0000 Original-Received: from localhost ([127.0.0.1]:59266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPp9M-0004nL-2X for submit@debbugs.gnu.org; Fri, 05 Sep 2014 04:45:44 -0400 Original-Received: from forward4l.mail.yandex.net ([84.201.143.137]:37284) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XPp9H-0004n3-B3 for 18410@debbugs.gnu.org; Fri, 05 Sep 2014 04:45:40 -0400 Original-Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [37.140.190.29]) by forward4l.mail.yandex.net (Yandex) with ESMTP id 919B214411B2; Fri, 5 Sep 2014 12:45:32 +0400 (MSK) Original-Received: from smtp4o.mail.yandex.net (localhost [127.0.0.1]) by smtp4o.mail.yandex.net (Yandex) with ESMTP id 0C4B52321770; Fri, 5 Sep 2014 12:45:31 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id PxId2sg86M-jTAOKZ9c; Fri, 5 Sep 2014 12:45:30 +0400 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: 3e05f8ae-75a7-4311-9222-d288dc780291 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1409906731; bh=s72vi3cEzPtz+F+G5wRAw0ATnM94tDldxcPXIX8aOxA=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=lJFPe6ZKsUuTPJNTYZfV9DjDoPpYVIswmk2ypWUxb7aH97g1xxRvw01Y0jyD8pcTL nrGSgmWnZ4x4i39pzba33aT79aKN6h+6qgYpwu0JepWCbfF/G1wjDx1I1x8Ohcl2lZ 39ZFJo6s8G/iDUNelKbI383vjdaJbMyYTRPidmJA= Authentication-Results: smtp4o.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: <5409536B.5090201@cs.ucla.edu> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:93062 Archived-At: On 09/05/2014 10:08 AM, Paul Eggert wrote: > Attached is a patch to fix the unbounded alloca calls that I found when auditing the Emacs source. > I'm sending this to bug-gnu-emacs to give Eli a heads-up, as some of the fixes affect Windows code. > This patch is relative to Emacs trunk bzr 117822. Code like: USE_SAFE_ALLOCA; |- ptrdiff_t count = SPECPDL_INDEX (); |- | ... | inner bind | outer bind Lisp_Object result = unbind_to (count, Fsome_func ()); |- | SAFE_FREE (); |- return result; looks suboptimal because it calls unbind_to twice. May be we need SAFE_FREE_RETURN, somewhat similar to RETURN_UNGCPRO? I.e. we should be able to say: USE_SAFE_ALLOCA; ptrdiff_t count = SPECPDL_INDEX (); ... SAFE_FREE_RETURN (Fsome_func ()); Minor note: why specbind can't return previous binding level? To avoid extra typing, someone can write: ptrdiff_t count = specbind (Qsome_var, Qnil); instead of: ptrdiff_t count = SPECPDL_INDEX (); specbind (Qsome_var, Qnil); Dmitry