Skip to content

malformed clang::SourceRange results in kaskara-statement-finder abort #62

@pdreiter

Description

@pdreiter

From the following log output, we can see that the getEndLoc() component of the DEBUG statement below refers to line 0, column 0, which results in an abort, due to improper length calculation from file offset.

DEBUG: obtained statement location: /workspace/source/catalog.c@2157:4::0:0
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create
/opt/kaskara/scripts/kaskara-statement-finder: line 5:    58 Aborted                 (core dumped) /opt/kaskara/bin/kaskara-statement-finder "$@"

With the location information above, we can see that the length calculation on ./lib/kaskara/clang/backend/src/util.cpp @ 61 would be negative.

 56 std::string read_source(clang::SourceManager const &SM, 
 57                         clang::SourceRange const &range)
 58 {
 59   clang::SourceLocation loc_start = range.getBegin();
 60   clang::SourceLocation loc_end = range.getEnd();
 61   int length = SM.getFileOffset(loc_end) - SM.getFileOffset(loc_start);
 62   const char *buff = SM.getCharacterData(loc_start);
 63   return llvm::StringRef(buff, length + 1).str();
 64 }

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions