`MEM53-CPP`: False positive due to flow through `realloc`

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

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

評価

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

調査の方向性

MEM53-CPP のテストケースと taint-tracking 設定の isSource 定義から始め、その後、realloc フローの変更に関するリンク先の pull request を確認してください。古い AST ベースのライブラリが realloc をどのように扱うか、また影響を受けるテストシナリオが妥当かどうかを判断してください。realloc による新しく割り当てられたメモリの再割り当てについて安全でない仮定を受け入れずに、false positive が解消されれば完了です。

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

説明

Difficulty-Medium false positive/false negative Impact-Low Stardard-CERT-C++
Affected rules
  • MEM53-CPP
Description

In https://github.com/github/codeql/pull/14637 we added taint-flow through the indirection of the pointer passed to realloc to the indirection of the result. That is, flow through the following example:

int* p = ...;
*p = tainted_value;
int* q = (int*)realloc(p, 1024);
sink(*p);

this relies on the new taint-tracking library to distinguish between the result of realloc(...), and the result of what realloc(...) points to. Since the old AST-based taint-tracking library cannot do this this results in a FP in the testcases for MEM53-CPP (that we accepted on the next branch here: https://github.com/github/codeql-coding-standards/pull/419)

The query already tries to rule out realloc cases by excluding them in the definition of the taint-tracking configuration's isSource, but to get this query back to not reporting a FP here a barrier on realloc would have to be inserted.

As @jketema points out the affected test is actually really sketchy since there’s no guarantee that memory allocated with new can safely be realloc'ed. So maybe this scenario should be thought about more carefully by someone on your team.

主要言語
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 を短くまとめたダイジェスト。