Fix segfault on incomplete types
authorPaul Chaignon <paul.chaignon@gmail.com>
Wed, 23 Aug 2017 05:25:30 +0000 (07:25 +0200)
committerBrenden Blanco <bblanco@gmail.com>
Wed, 23 Aug 2017 17:18:38 +0000 (10:18 -0700)
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

index 87ed228b08ecc7c3924e1e4882fb0ca2fdcf98f0..c6218ff4e73bffe8ebf3ff80a37513efc906f619 100644 (file)
@@ -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) {