posit-dev / posit-dev/ark

Maybe unsound in RLocal::new

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

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

主要言語
Rust
スター
337
フォーク
32
平均マージ
8日 17時間
マージ済み PR(30日)
11

説明

Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:

pub struct RLocal<T: Copy> {
    old_value: T,
    variable: *mut T,
}

impl<T> RLocal<T>
where
    T: Copy,
{
    pub fn new(new_value: T, variable: *mut T) -> RLocal<T> {
        unsafe {
            let old_value = libr::get(variable);
            libr::set(variable, new_value);

            Self {
                old_value,
                variable,
            }
        }
    }
}

Considering that pub mod raii, and new is also a pub function. I assume that users can directly call this function. This potential situation could result in libr::get being called to a null pointer, and might trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.
I suggest Several possible fixes:

  1. If there is no external usage for RLocal or new, they should not marked as pub, at least its new should not marked as pub
  2. new method should add additional check for null pointer.
  3. mark new method as unsafe and proper doc to let users know that they should provide valid Pointers.

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

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

はじめの一歩

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

調査の方向性

まず公開されている raii モジュールと RLocal::new を見つけ、次に libr::get と libr::set 周辺の呼び出し元とポインタに関する前提を調べます。API が null ポインタまたはその他の無効なポインタを受け取る可能性があるかを確認します。安全性の契約または可視性が明確になり、報告された未定義動作の経路に対処できれば完了です。

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

評価

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

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

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