]> granicus.if.org Git - clang/commit
[index] Return when DC is null in handleReference
authorFangrui Song <maskray@google.com>
Mon, 8 Jan 2018 18:57:38 +0000 (18:57 +0000)
committerFangrui Song <maskray@google.com>
Mon, 8 Jan 2018 18:57:38 +0000 (18:57 +0000)
commitf0f28f26f24592df4e78ffbf770f0e514dea2c4f
treefcd7d0a92b4dc08fb68f988f24ccf3f377e17f62
parent4dbfa35100a717e11dd91fae9c5e6f47d666933a
[index] Return when DC is null in handleReference

Summary:
DC may sometimes be NULL and getContainerInfo(DC, Container) will dereference a null pointer.

Default template arguments (the following example and many test files in https://github.com/nlohmann/json)
may cause null pointer dereference.

```c++
template <typename>
struct actor;

template <template <typename> class Actor = actor>
struct terminal;
```

In tools/libclang/CXIndexDataConsumer.cpp#L203

    handleReference(ND, Loc, Cursor,
                    dyn_cast_or_null<NamedDecl>(ASTNode.Parent),
                    ASTNode.ContainerDC, ASTNode.OrigE, Kind);

`dyn_cast_or_null<NamedDecl>(ASTNode.Parent)` is somehow a null pointer and in tools/libclang/CXIndexDataConsumer.cpp:935

  ContainerInfo Container;
  getContainerInfo(DC, Container);

The null DC is casted `ContInfo.cursor = getCursor(cast<Decl>(DC));` and SIGSEGV.

```

See discussions in https://github.com/jacobdufault/cquery/issues/219 https://github.com/jacobdufault/cquery/issues/192

Reviewers: akyrtzi, sammccall, yvvan

Reviewed By: sammccall

Subscribers: mehdi_amini, cfe-commits

Differential Revision: https://reviews.llvm.org/D41575

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322017 91177308-0d34-0410-b5e6-96231b3b80d8
tools/libclang/CXIndexDataConsumer.cpp