From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Chris Feng Newsgroups: gmane.emacs.bugs Subject: bug#24118: 25.1; [PATCH] Fix a possible crash caused by mapcar1 Date: Sun, 31 Jul 2016 20:46:50 +0800 Message-ID: <86fuqq2cw5.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1469969311 19089 80.91.229.8 (31 Jul 2016 12:48:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 31 Jul 2016 12:48:31 +0000 (UTC) To: 24118@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 31 14:48: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 1bTqAC-0004tB-9o for geb-bug-gnu-emacs@m.gmane.org; Sun, 31 Jul 2016 14:48:16 +0200 Original-Received: from localhost ([::1]:39542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTqA8-00049H-Fd for geb-bug-gnu-emacs@m.gmane.org; Sun, 31 Jul 2016 08:48:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTqA2-000499-Et for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:48:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTq9y-0004xb-A2 for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:48:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54688) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTq9y-0004xX-6r for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bTq9y-0008B8-1i for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Chris Feng Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 Jul 2016 12:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24118 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.146996923431378 (code B ref -1); Sun, 31 Jul 2016 12:48:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Jul 2016 12:47:14 +0000 Original-Received: from localhost ([127.0.0.1]:51985 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTq9C-0008A2-Lp for submit@debbugs.gnu.org; Sun, 31 Jul 2016 08:47:14 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54194) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTq9B-00089q-QN for submit@debbugs.gnu.org; Sun, 31 Jul 2016 08:47:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTq95-0004vq-SN for submit@debbugs.gnu.org; Sun, 31 Jul 2016 08:47:08 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:41682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTq95-0004vl-PZ for submit@debbugs.gnu.org; Sun, 31 Jul 2016 08:47:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTq93-0003rk-MS for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:47:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTq8z-0004vQ-Il for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:47:04 -0400 Original-Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTq8z-0004vM-As for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 08:47:01 -0400 Original-Received: by mail-pf0-x244.google.com with SMTP id g202so8487920pfb.1 for ; Sun, 31 Jul 2016 05:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version; bh=VoT5n+v2IaCscqcyeLkCCz82mxoTD/vnSNiJaCg1eIM=; b=arRndn4tXJjijKuwcT26g61mW0tmq96TGhKZE8VzEO2Ht72wkH8UVO83TPxjKb5f1N t18qMPSu7XO4Z2uEn5FLCQHDf1lGd/SRtvQnEHORcY21sIct+uRLuQm6X5bQ7jslBfbl 0m5aEx9eGtih3lRJ+4sf5M5GIexWDPm8P8x4Ka5QkZRW2QCm23zOzka+1tb9qJVOhneO 5EBzwy1iW4Goat/4FZBjZvyd0s/SvKT6hAH3aAIlTxkIjoUEsPjNIavHKNr1shMSQ/NR sIIsh4OIQqeh+nJk8UbSokuo/3fm/370KGkvCQb6XMbyQi7zRDgGXM9QG6AWV6d+h4IZ 8cLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=VoT5n+v2IaCscqcyeLkCCz82mxoTD/vnSNiJaCg1eIM=; b=WrTUgsfhS0Mi33UMfCG56/kXf5MrQ9o5Lp/4DVueh4v9z2HIfEOcsOxGOzH1LCJqkk 014ilZ6TrWFRpBepcvOrWIMbGVDpjGD9DvQEg62GT6P/xpYddqkC/xhESjL1YhHCuqa1 oM68ecSvOv1BUtHtjSvcCOkY6Sw/U8HIgNwbeir+++Lic6VUJI9GqsSuLcyjthj6k4Q3 4WgT5bYh+ypsobexOuPJfw34zQUxceQTgQXrmHh4GBwcGjtzdQhkjbMZZHWe2tBmUd52 N7lfsvXrGif6Lcr1e4WwSou5THVMiY2Exogr3ZmYethYFSO/6/9VtoK+xmXsUTExx9sz 01qw== X-Gm-Message-State: AEkoousEv0j+PoAAmlNBZoY2f6s7M4SqHt3L7wV/rsffrZVGFlZmp6hXKAz3EKy6ZoQSsA== X-Received: by 10.98.155.17 with SMTP id r17mr86302496pfd.24.1469969219708; Sun, 31 Jul 2016 05:46:59 -0700 (PDT) Original-Received: from tpx ([209.141.62.125]) by smtp.gmail.com with ESMTPSA id wp4sm38213646pab.15.2016.07.31.05.46.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 31 Jul 2016 05:46:58 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:121733 Archived-At: Processing a list with `mapcar' or `mapconcat' can be terminated early when the list is tampered (as shown in the following example), and as a result we'll be dealing with uninitialized memory which will likely trigger a crash. (setq a (make-list 10 0)) (mapcar (lambda (_) (setcdr a nil)) a) Chris --- * src/fns.c (mapcar1): Check and reset uninitialized list elements. --- src/fns.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fns.c b/src/fns.c index d5a1f74..1804bce 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2524,6 +2524,10 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) vals[i] = dummy; tail = XCDR (tail); } + + /* In case the list was tampered and the loop terminated early. */ + if (i < leni) + memclear (vals + i, (leni - i) * word_size); } } -- 2.8.1