1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
From: Bram Moolenaar <Bram@vim.org>
Date: Sun, 17 Jun 2018 17:32:58 +0200
Subject: patch 8.1.0066: nasty autocommand causes using freed memory
Problem: Nasty autocommand causes using freed memory. (Dominique Pelle)
Solution: Do not force executing autocommands if the value of 'syntax' or
'filetype' did not change.
(cherry picked from commit c3ffc9b8d3015dc5280b297b4e3deb4f34944bd4)
Signed-off-by: James McCoy <jamessan@debian.org>
---
src/option.c | 18 ++++++++++++------
src/version.c | 2 ++
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/option.c b/src/option.c
index 0986ef6..056292f 100644
--- a/src/option.c
+++ b/src/option.c
@@ -5866,7 +5866,7 @@ did_set_string_option(
int redraw_gui_only = FALSE;
#endif
#ifdef FEAT_AUTOCMD
- int ft_changed = FALSE;
+ int value_changed = FALSE;
#endif
/* Get the global option to compare with, otherwise we would have to check
@@ -7261,7 +7261,7 @@ did_set_string_option(
if (!valid_filetype(*varp))
errmsg = e_invarg;
else
- ft_changed = STRCMP(oldval, *varp) != 0;
+ value_changed = STRCMP(oldval, *varp) != 0;
}
#endif
@@ -7270,6 +7270,8 @@ did_set_string_option(
{
if (!valid_filetype(*varp))
errmsg = e_invarg;
+ else
+ value_changed = STRCMP(oldval, *varp) != 0;
}
#endif
@@ -7369,20 +7371,24 @@ did_set_string_option(
/* When 'syntax' is set, load the syntax of that name */
if (varp == &(curbuf->b_p_syn))
{
+ // Only pass TRUE for "force" when the value changed, to avoid
+ // endless recurrence. */
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
- curbuf->b_fname, TRUE, curbuf);
+ curbuf->b_fname, value_changed, curbuf);
}
# endif
else if (varp == &(curbuf->b_p_ft))
{
/* 'filetype' is set, trigger the FileType autocommand.
* Skip this when called from a modeline and the filetype was
- * already set to this value. */
- if (!(opt_flags & OPT_MODELINE) || ft_changed)
+ * already set to this value.
+ * Only pass TRUE for "force" when the value changed, to avoid
+ * endless recurrence. */
+ if (!(opt_flags & OPT_MODELINE) || value_changed)
{
did_filetype = TRUE;
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
- curbuf->b_fname, TRUE, curbuf);
+ curbuf->b_fname, value_changed, curbuf);
}
}
#endif
diff --git a/src/version.c b/src/version.c
index 36e20ce..f8f34d4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -1195,6 +1195,8 @@ static int included_patches[] =
*/
static char *(extra_patches[]) =
{ /* Add your patch description below this line */
+/**/
+ "8.1.0066",
/**/
NULL
};
|