[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/native-comp 10933f2 1/2: Copy suffixes passed to 'openp' to avoi
From: |
Andrea Corallo |
Subject: |
feature/native-comp 10933f2 1/2: Copy suffixes passed to 'openp' to avoid GC crashes. Fixes bug#41755 |
Date: |
Wed, 10 Jun 2020 08:34:16 -0400 (EDT) |
branch: feature/native-comp
commit 10933f235fa2f1d7a3936da173cdd6e807bff57f
Author: Nicolás Bértolo <nicolasbertolo@gmail.com>
Commit: Andrea Corallo <andrea.corallo@arm.com>
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 a3e8d07..0530848 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);