CppDepend で CWE コンプライアンスを確保し、C/C++ コードのセキュリティを強化
CppDepend で CWE コンプライアンスを確保し、C/C++ コードのセキュリティを強化
ソフトウェア開発の世界では、安全なコーディングプラクティスの遵守が、アプリケーションやシステムを潜在的な脅威から保護するために不可欠です。CWE(Common Weakness Enumeration)コンプライアンスの達成は、このプロセスにおける重要なステップです。CppDepend は、C/C++ 開発者が CWE コンプライアンスを確保するための堅牢なソリューションを提供し、コードのセキュリティとソフトウェア全体の品質を効果的に強化します。
このガイドでは、CWE コンプライアンスのために CppDepend を使用する利点を探ります。脆弱性の特定と軽減、コード品質の向上、C/C++ プロジェクトにおける安全なコーディングプラクティスの促進のための強力な機能が含まれます。
CppDependでのCWEルールの使用
新しい CppDepend プロジェクトを作成すると、分析に含めたいすべてのコーディング標準を表示するポップアップが表示されます。CWE コーディング標準を含めるには、CWE オプションをチェックします。

プロジェクトを分析した後、Queries and Rules Explorer セクションに移動し、左側のメニューから CWE Rules を選択します(下の画像で赤く強調表示)。これにより、関連するすべての CWE ルールが右側に表示されます。ルールをクリックすると、対応する CQLinq クエリと関連するソースコードが自動的に生成されます。さらに、Metrics View セクションでは、問題の場所と重要性のビジュアライゼーションが提供されます。

CWEルールをHTMLレポートに組み込む
生成された HTML レポート(DevOps Edition で利用可能)に CWE ルールを含めるには、CWE グループを右クリックして「List Code Queries of this Group in a dedicated section in Report」を選択するだけです。

CWEルール
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow'):
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck"
&& (issue.Type=="bufferAccessOutOfBounds" || issue.Type=="possibleBufferAccessOutOfBounds"
|| issue.Type=="insecureCmdLineArgs"|| issue.Type=="invalidscanf") select
new { issue,issue.FilePath,Line=issue.BeginLine}ゼロ除算:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="zerodiv" select
new { issue,issue.FilePath,Line=issue.BeginLine}未チェックのエラー条件:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="zerodiv" select
new { issue,issue.FilePath,Line=issue.BeginLine}汎用例外のcatch宣言:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from m in **Methods** where !m.IsEntryPoint
&& m.IsUsing("Keywords.generic_catch".AllowNoMatch()) select mImproper Release of Memory Before Removing Last Reference ('Memory Leak'):
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && (issue.Type=="memleak" || issue.Type=="memleakOnRealloc"
|| issue.Type=="publicAllocationError"|| issue.Type=="leakNoVarFunctionCall") select
new { issue,issue.FilePath,Line=issue.BeginLine}二重解放:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="deallocDealloc" select
new { issue,issue.FilePath,Line=issue.BeginLine}未初期化変数の使用:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="uninitvar"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}不完全なクリーンアップ:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="resourceLeak" select
new { issue,issue.FilePath,Line=issue.BeginLine}NULLポインタの逆参照:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="nullPointer" select
new { issue,issue.FilePath,Line=issue.BeginLine}廃止関数の使用:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CLang" && issue.Type=="warn_deprecated" select
new { issue,issue.FilePath,Line=issue.BeginLine}代入ではなく比較:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CLang" && issue.Type=="warn_unused_comparison" select
new { issue,issue.FilePath,Line=issue.BeginLine}switch内のbreak文の欠落:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_unannotated_fallthrough" select
new { issue,issue.FilePath,Line=issue.BeginLine}デッドコード:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_unreachable" select
new { issue,issue.FilePath,Line=issue.BeginLine}Assignment to Variable without Use ('Unused Variable'):
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="unreadVariable"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **2**.ToMinutes().ToDebt(),
Severity =Severity.Low
}式は常に偽:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="knownConditionTrueFalse"
&& issue.Description.Contains("always false")
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **2**.ToMinutes().ToDebt(),
Severity =Severity.Low
}式は常に真:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="knownConditionTrueFalse"
&& issue.Description.Contains("always true")
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **2**.ToMinutes().ToDebt(),
Severity =Severity.Low
}Function Call with Incorrectly Specified Arguments:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="preprocessorErrorDirective"
&& issue.Description.Contains("Wrong number")
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **2**.ToMinutes().ToDebt(),
Severity =Severity.Low
}潜在的に危険な関数の使用:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="dangerousUsageStrtol"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **2**.ToMinutes().ToDebt(),
Severity =Severity.Low
}演算子優先順位の論理エラー:
このコーディング標準は次のクエリで計算されます:
warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && (issue.Type=="clarifyCalculation"
|| issue.Type=="clarifyCondition")
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **2**.ToMinutes().ToDebt(),
Severity =Severity.Low
}