From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: [PATCH] bug in org-babel-execute-src-block Date: Thu, 18 Apr 2013 04:16:16 -0400 Message-ID: <877gk0s17z.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:45810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USk0z-0002CW-0v for emacs-orgmode@gnu.org; Thu, 18 Apr 2013 04:16:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USk0w-0000Mi-8b for emacs-orgmode@gnu.org; Thu, 18 Apr 2013 04:16:20 -0400 Received: from mail-vc0-f175.google.com ([209.85.220.175]:42050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USk0w-0000M8-43 for emacs-orgmode@gnu.org; Thu, 18 Apr 2013 04:16:18 -0400 Received: by mail-vc0-f175.google.com with SMTP id ib11so2152284vcb.20 for ; Thu, 18 Apr 2013 01:16:17 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, I=E2=80=99ve discovered a bug in org-babel-execute-src-block. Calls to set= f can leak outside of the function and affect the library of babel. The attached org file illustrates the problem. The attached patch fixes it. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=lob-bug.org * Bug Step 1: place the foo code block below into a different file and ingest that file into the library of babel. (It must be in a separate file for the bug to manifest.) #+name: foo #+BEGIN_SRC emacs-lisp 2 #+END_SRC Step 2: evaluate this code block. The result should be =(:results . replace)= #+BEGIN_SRC emacs-lisp :results append (assq :results (nth 2 (cdr (assq 'foo org-babel-library-of-babel)))) #+END_SRC #+RESULTS: : (:results . replace) : (:results . silent) Step 3: evaluate this source block: #+BEGIN_SRC emacs-lisp :var bar=foo bar #+END_SRC #+RESULTS: : 2 Step 4: re-evaluate the block from step 2. The result should be =(:results . silent)= --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0004-Fix-bug-in-org-babel-execute-src-block.patch >From 84531966dc5ca50fb56c61726694e988da3053eb Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Thu, 18 Apr 2013 04:02:47 -0400 Subject: [PATCH 4/4] Fix bug in org-babel-execute-src-block * lisp/ob-core.el (org-babel-execute-src-block): copy the info Otherwise, the setf calls in this function can reach into and change other configuration variables, such as the library of babel. --- lisp/ob-core.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 12fcecc..71e9d61 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -547,7 +547,9 @@ Optionally supply a value for PARAMS which will be merged with the header arguments specified at the front of the source code block." (interactive) - (let* ((info (or info (org-babel-get-src-block-info))) + (let* ((info (if info + (copy-tree info) + (org-babel-get-src-block-info))) (merged-params (org-babel-merge-params (nth 2 info) params))) (when (org-babel-check-evaluate (let ((i info)) (setf (nth 2 i) merged-params) i)) -- 1.8.2.1 --=-=-= Content-Type: text/plain -- Aaron Ecay --=-=-=--