unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Nicolas Bértolo" <nicolasbertolo@gmail.com>
To: 41755@debbugs.gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>, Pip Cet <pipcet@gmail.com>,
	Andrea Corallo <akrl@sdf.org>
Subject: bug#41755: feature/native-comp (master?): temacs crash in GC during mark phase
Date: Tue, 9 Jun 2020 11:20:01 -0300	[thread overview]
Message-ID: <CAFnS-OmrvF7P8zb26wNBpOq-CG0KAMAsjbb85e6B=aCda=ZEAA@mail.gmail.com> (raw)
In-Reply-To: <87tuzlwf82.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

Hi,

Here's a new patch that copies the suffixes before building the heap-based list
in openp. I know this is not the solution I proposed, but I couldn't adapt the
code without increasing its complexity way too much for my liking. If you think
this is not an appropriate solution I will come up with another one.

Thanks, Nico.

[-- Attachment #2: 0001-Copy-suffixes-passed-to-openp-to-avoid-GC-crashes.-F.patch --]
[-- Type: application/octet-stream, Size: 2209 bytes --]

From 4b4fd526abe124c8a74bfa11209dd53c3a564cc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=A1s=20B=C3=A9rtolo?= <nicolasbertolo@gmail.com>
Date: Mon, 8 Jun 2020 22:01:25 -0300
Subject: [PATCH] Copy suffixes passed to 'openp' to avoid GC crashes. Fixes
 bug#41755

In openp_add_middle_dir_to_suffixes we build a heap-based list from
the passed suffixes.  It is crucial that we don't create a heap-based
cons that points to a stack-based list.

* src/lread.c (openp_add_middle_dir_to_suffixes): Copy suffixes when
building a list of middle-dirs and suffixes.
---
 src/lread.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/lread.c b/src/lread.c
index c127d32eb17..65d84462c4c 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1635,21 +1635,27 @@ openp_add_middle_dir_to_suffixes (Lisp_Object suffixes)
   Lisp_Object extended_suf = Qnil;
   FOR_EACH_TAIL_SAFE (tail)
     {
-#ifdef HAVE_NATIVE_COMP
+      /*  suffixes may be a stack-based cons pointing to stack-based
+          strings.  We must copy the suffix if we are putting it into
+          a heap-based cons to avoid a dangling reference.  This would
+          lead to crashes during the GC.  */
       CHECK_STRING_CAR (tail);
       char * suf = SSDATA (XCAR (tail));
+      Lisp_Object copied_suffix = build_string (suf);
+#ifdef HAVE_NATIVE_COMP
       if (strcmp (NATIVE_ELISP_SUFFIX, suf) == 0)
         {
           CHECK_STRING (Vcomp_native_path_postfix);
           /* Here we add them in the opposite order so that nreverse
              corrects it.  */
-          extended_suf = Fcons (Fcons (Qnil, XCAR (tail)), extended_suf);
-          extended_suf = Fcons (Fcons (Vcomp_native_path_postfix, XCAR (tail)),
+          extended_suf = Fcons (Fcons (Qnil, copied_suffix), extended_suf);
+          extended_suf = Fcons (Fcons (Vcomp_native_path_postfix,
+                                       copied_suffix),
                                 extended_suf);
         }
       else
 #endif
-	extended_suf = Fcons (Fcons (Qnil, XCAR (tail)), extended_suf);
+	extended_suf = Fcons (Fcons (Qnil, copied_suffix), extended_suf);
     }
 
   suffixes = Fnreverse (extended_suf);
-- 
2.25.1.windows.1


  reply	other threads:[~2020-06-09 14:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-07 19:16 bug#41755: feature/native-comp (master?): temacs crash in GC during mark phase Andrea Corallo
2020-06-07 19:41 ` Pip Cet
2020-06-07 19:57   ` Nicolas Bértolo
2020-06-07 20:18     ` Pip Cet
2020-06-07 23:09       ` Nicolas Bértolo
2020-06-08  3:39         ` Nicolas Bértolo
2020-06-08  6:29           ` Eli Zaretskii
2020-06-08 18:24             ` Nicolas Bértolo
2020-06-08  6:41           ` Pip Cet
2020-06-08 18:51             ` Nicolas Bértolo
2020-06-08 19:05               ` Pip Cet
2020-06-09 14:20                 ` Nicolas Bértolo [this message]
2020-06-10 12:53                   ` Andrea Corallo
2020-06-27 14:39                     ` Andrea Corallo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFnS-OmrvF7P8zb26wNBpOq-CG0KAMAsjbb85e6B=aCda=ZEAA@mail.gmail.com' \
    --to=nicolasbertolo@gmail.com \
    --cc=41755@debbugs.gnu.org \
    --cc=akrl@sdf.org \
    --cc=eggert@cs.ucla.edu \
    --cc=pipcet@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).