From 52e371129ae6b81481396defa3e7f9bc93ca5c02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0torc?= <storcond@fit.cvut.cz>
Date: Tue, 28 Mar 2023 13:35:29 +0200
Subject: [PATCH] cli: Check parser output before transforming AST

---
 alib2cli/src/parser/Parser2.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/alib2cli/src/parser/Parser2.cpp b/alib2cli/src/parser/Parser2.cpp
index 6da9503d8..3de7cc0b7 100644
--- a/alib2cli/src/parser/Parser2.cpp
+++ b/alib2cli/src/parser/Parser2.cpp
@@ -38,12 +38,17 @@ std::unique_ptr<CommandList> Parser2::parse(antlr4::CharStream& stream)
     parser.setErrorHandler(std::make_shared<antlr4::DefaultErrorStrategy>());
 
     AltCliParser::ParseContext* tree = parser.parse();
-    auto command = AltVisitor().transform(tree);
-
     if (listener->any()) {
         throw exception::CommonException(listener->getErrors());
     }
 
+    if (tree == nullptr) {
+        throw exception::CommonException("Invalid parse");
+    }
+
+    auto command = AltVisitor().transform(tree);
+
+
     return command;
 }
 } // cli
-- 
GitLab