Skip to content

Commit

Permalink
Fix perf_submit() calls with array data crashing libbcc
Browse files Browse the repository at this point in the history
A perf_submit() call like:

	unsigned char buf[16] = ...;
	output.perf_submit(ctx, buf, sizeof(buf));

Passes a non-pointer arg1, so getPointeeType().getTypePtr() is invalid,
and crashes libbcc.
Use getTypePtrOrNull() instead to avoid it.

Signed-off-by: Yonatan Goldschmidt <[email protected]>
  • Loading branch information
Jongy authored and yonghong-song committed Dec 29, 2020
1 parent 8fac710 commit 9541149
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
// events.perf_submit(ctx, &data, sizeof(data));
// ...
// &data -> data -> typeof(data) -> data_t
auto type_arg1 = Call->getArg(1)->IgnoreCasts()->getType().getTypePtr()->getPointeeType().getTypePtr();
if (type_arg1->isStructureType()) {
auto type_arg1 = Call->getArg(1)->IgnoreCasts()->getType().getTypePtr()->getPointeeType().getTypePtrOrNull();
if (type_arg1 && type_arg1->isStructureType()) {
auto event_type = type_arg1->getAsTagDecl();
const auto *r = dyn_cast<RecordDecl>(event_type);
std::vector<std::string> perf_event;
Expand Down

0 comments on commit 9541149

Please sign in to comment.