libdparse
libdparse copied to clipboard
Out of bounds access when parsing PragmaExpression
Forwarding from Basile
Patch:
From d4300b3d1f60717ed5698b2b33eb89b0bbd05ba1 Mon Sep 17 00:00:00 2001
From: Basile Burg
Date: Mon, 27 Apr 2020 16:58:34 +0200
Subject: [PATCH] fix out of bounds access when parsing PragmaExpression
---
src/dparse/parser.d | 3 ++-
test/fail_files/pragma_exp_bound.d | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
create mode 100644 test/fail_files/pragma_exp_bound.d
diff --git a/src/dparse/parser.d b/src/dparse/parser.d
index bdebe18..59d8fa2 100644
--- a/src/dparse/parser.d
+++ b/src/dparse/parser.d
@@ -5192,7 +5192,8 @@ class Parser
advance();
mixin(parseNodeQ!(`node.argumentList`, `ArgumentList`));
}
- expect(tok!")");
+ auto rightParen = expect(tok!")");
+ mixin(nullCheck!`rightParen`);
node.tokens = tokens[startIndex .. index];
return node;
}
diff --git a/test/fail_files/pragma_exp_bound.d b/test/fail_files/pragma_exp_bound.d
new file mode 100644
index 0000000..0fb7573
--- /dev/null
+++ b/test/fail_files/pragma_exp_bound.d
@@ -0,0 +1,3 @@
+void main() {
+ pragma(msg F
+}
--
2.25.4
I think that the real problem here is that the code is calling expect when it should be doing a mixin(tokenCheck!. It seems that this problem is kind of widespread in the parser.