From bee8b8f851823833c98b1fb30f938de114984ed8 Mon Sep 17 00:00:00 2001 From: urandon Date: Mon, 22 May 2023 19:00:08 +0300 Subject: [PATCH] [clang-tidy] Fixes the crash in openharmony checker Performs early exit in PrintSensitiveInfoChecker when expression direct callee in not available Tests: locally Relates: https://gitee.com/open_harmony/dashboard?issue_id=I6YLJ9 Signed-off-by: urandon --- .../Checkers/OpenHarmony/PrintSensitiveInfoChecker.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/PrintSensitiveInfoChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/PrintSensitiveInfoChecker.cpp index 9647f99a4c5f..7fa15c77d81c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/PrintSensitiveInfoChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/PrintSensitiveInfoChecker.cpp @@ -120,6 +120,8 @@ const VarDecl *PrintSensitiveInfoChecker::GetVarDeclFromExpr(const Expr *E) cons } string PrintSensitiveInfoChecker::GetCurrentCalleeName(const CallExpr *CE) const { + assert(CE); + assert(CE->getDirectCallee()); return CE->getDirectCallee()->getNameInfo().getName().getAsString(); } @@ -198,7 +200,7 @@ void PrintSensitiveInfoChecker::checkPreStmt(const BinaryOperator *binary, Check } void PrintSensitiveInfoChecker::checkPreStmt(const CallExpr *call, CheckerContext &c) const { - if (call == nullptr) { + if (!call || !call->getDirectCallee()) { return; } string funcName = GetCurrentCalleeName(call); @@ -248,6 +250,9 @@ void PrintSensitiveInfoChecker::saveVardeclStateForBo(const Expr *lhs, const Exp } if (isa(rhs)) { const CallExpr *call = llvm::dyn_cast_or_null(rhs); + if (!call || !call->getDirectCallee()) { + return; + } string funcName = GetCurrentCalleeName(call); if (m_sensitive_func_set.find(convertStrToLowerCase(funcName)) != m_sensitive_func_set.end()) { ProgramStateRef state = c.getState(); @@ -272,6 +277,9 @@ void PrintSensitiveInfoChecker::saveVardeclStateForDeclStmt(const DeclStmt *ds, if (isa(expr)) { const CallExpr *call = llvm::dyn_cast_or_null(expr); + if (!call || !call->getDirectCallee()) { + return; + } string funcName = GetCurrentCalleeName(call); if (m_sensitive_func_set.find(convertStrToLowerCase(funcName)) != m_sensitive_func_set.end()) { ProgramStateRef state = c.getState(); -- Gitee