summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-18 04:58:15 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-18 04:58:15 +1100
commit7ba4ef897bbc7e6c7b65ccf01f4085ed86cd04d6 (patch)
treeeb778c3176669a504364a99ffb09ffa38396fd45
parent0a2807e6526bf386e0dbf4516d4819a97e46f2bb (diff)
Fix crash on expanding command line strings
-rw-r--r--src/command_manager.cc5
-rw-r--r--test/regression/0-crash-on-specialy-crafted-modeline/cmd1
-rw-r--r--test/regression/0-crash-on-specialy-crafted-modeline/in1
-rw-r--r--test/regression/0-crash-on-specialy-crafted-modeline/out1
-rw-r--r--test/regression/0-crash-on-specialy-crafted-modeline/rc1
5 files changed, 8 insertions, 1 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index ac6ef56a..8d400a64 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -168,6 +168,7 @@ void skip_blanks_and_comments(Reader& reader)
Token parse_percent_token(Reader& reader, bool throw_on_unterminated)
{
+ kak_assert(*reader == '%');
++reader;
const auto type_start = reader.pos;
while (reader and iswalpha(*reader))
@@ -340,7 +341,9 @@ String expand_impl(StringView str, const Context& context,
Codepoint c = *reader;
if (c == '\\')
{
- c = *++reader;
+ if (not (++reader))
+ throw parse_error{"unterminated escape"};
+ c = *reader;
if (c == '%' or c == '\\')
{
res += reader.substr_from(beg);
diff --git a/test/regression/0-crash-on-specialy-crafted-modeline/cmd b/test/regression/0-crash-on-specialy-crafted-modeline/cmd
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/regression/0-crash-on-specialy-crafted-modeline/cmd
@@ -0,0 +1 @@
+
diff --git a/test/regression/0-crash-on-specialy-crafted-modeline/in b/test/regression/0-crash-on-specialy-crafted-modeline/in
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/regression/0-crash-on-specialy-crafted-modeline/in
@@ -0,0 +1 @@
+
diff --git a/test/regression/0-crash-on-specialy-crafted-modeline/out b/test/regression/0-crash-on-specialy-crafted-modeline/out
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/regression/0-crash-on-specialy-crafted-modeline/out
@@ -0,0 +1 @@
+
diff --git a/test/regression/0-crash-on-specialy-crafted-modeline/rc b/test/regression/0-crash-on-specialy-crafted-modeline/rc
new file mode 100644
index 00000000..d0ebe7c3
--- /dev/null
+++ b/test/regression/0-crash-on-specialy-crafted-modeline/rc
@@ -0,0 +1 @@
+set global modelinefmt %{\}