From 3e004dcb36fea0fb43f1ff9f8e01ca0bfa3e41ee Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Thu, 3 Dec 2020 17:41:11 +0100
Subject: [PATCH] Fixed segmentation fault when trying to access the
 constructor of an erroneous class type (Bug 568899)

Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
Change-Id: I8157e9098cf6e558e8a9a4a5bb1461f4931eb376
---
 compiler2/Value.cc           | 7 +++++--
 compiler2/ttcn3/AST_ttcn3.cc | 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/compiler2/Value.cc b/compiler2/Value.cc
index f4d08677f..706f380f6 100644
--- a/compiler2/Value.cc
+++ b/compiler2/Value.cc
@@ -8822,9 +8822,12 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
           error("Cannot create an instance of abstract class type `%s'",
             class_->get_my_def()->get_Type()->get_typename().c_str());
         }
-        Ttcn::FormalParList* fp_list = class_->get_constructor()->get_FormalParList();
+        Common::Assignment* constructor = class_->get_constructor();
+        Ttcn::FormalParList* fp_list = (constructor != NULL) ?
+          constructor->get_FormalParList() : NULL;
         Ttcn::ActualParList* parlist = new Ttcn::ActualParList;
-        bool is_erroneous = fp_list->chk_actual_parlist(u.expr.t_list2->get_tis(), parlist);
+        bool is_erroneous = (constructor != NULL) ?
+          fp_list->chk_actual_parlist(u.expr.t_list2->get_tis(), parlist) : true;
         if (is_erroneous) {
           delete parlist;
           parlist = 0;
diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc
index ff46e56ee..d41b73d93 100644
--- a/compiler2/ttcn3/AST_ttcn3.cc
+++ b/compiler2/ttcn3/AST_ttcn3.cc
@@ -883,6 +883,9 @@ namespace Ttcn {
             // if the referred assignment is a class type, then the reference and
             // its parameters are meant for the constructor instead
             ass = type->get_class_type_body()->get_constructor();
+            if (ass == NULL) {
+              return NULL;
+            }
           }
         }
         FormalParList* fplist = ass->get_FormalParList();
-- 
GitLab