`EXP39-C`: False positives related to compatible types, harmless casts

オープン
#1,200 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cpp
領域
devtools

調査の方向性

Start with the EXP39-C implementation and compare its compatibleTypes predicate with common/types/Compatible.qll, paying particular attention to typedefs and pointer compatibility. Review how casted expressions are modeled as sources and sinks, then use the provided typedef and unused-cast examples to verify that harmless casts are no longer reported.

索引モデルが issue の本文から書いたものです。

説明

Difficulty-Medium false positive/false negative false-positive Impact-Medium Standard-CERT-C
Affected rules
  • EXP39-C
Description

First off, our implementation uses a compatibleTypes predicate that is incomplete and doesn't handle typedefs, and should be replaced with our common/types/Compatible.qll library. This results in thousands of false positives in certain codebases, usually due to casting to a project-specific typedef of a byte like GLBYTE*.

Secondly, while we use dataflow to trace realloc's that flow to a deref without a memset, we don't use dataflow to handle the more typical case of A* cast to B* followed by a deref. Instead, we have a type representing casted expressions that's both a sink and a source. (We check compatibility of the pointers in the cast in the select statement). This isn't strictly UB unless the pointer is dereferenced, and I do see examples of this in real code. As a related example, casts to void** are often flagged while void* is excluded. This isn't a rare exceptional use of void, it's really just a harmless cast.

Example
typedef char BYTE;
void example_function() {
  int x;
  (long *) &x; // harmless since it's unused
  BYTE *x_bytes = (BYTE *)&x; // Allowed since BYTE is a char.
}
主要言語
CodeQL
スター
227
フォーク
82
平均マージ
6日 7時間
マージ済み PR(30日)
9

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/codeql-coding-standards のほかの issue

github/codeql-coding-standards の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。