From d32a61b076ded297afab5bbbb7fd6178ee274e71 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Wed, 23 Aug 2017 07:25:30 +0200 Subject: [PATCH] Fix segfault on incomplete types The bcc rewriter segfaults when it encounters an incomplete type (missing declaration or declaration after use) in a map declaration. This commit fixes it by first checking the type and returning an error if it is incomplete. --- src/cc/frontends/clang/b_frontend_action.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc index 87ed228b..c6218ff4 100644 --- a/src/cc/frontends/clang/b_frontend_action.cc +++ b/src/cc/frontends/clang/b_frontend_action.cc @@ -621,6 +621,11 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) { unsigned i = 0; for (auto F : RD->fields()) { + if (F->getType().getTypePtr()->isIncompleteType()) { + error(F->getLocStart(), "unknown type"); + return false; + } + size_t sz = C.getTypeSize(F->getType()) >> 3; if (F->getName() == "key") { if (sz == 0) { -- 2.34.1