Maybe unsound in RLocal::new
まだ誰も着手していません。
- 主要言語
- 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:
- If there is no external usage for
RLocalornew, they should not marked aspub, at least itsnewshould not marked aspub newmethod should add additional check for null pointer.- mark new method as unsafe and proper doc to let users know that they should provide valid Pointers.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず公開されている raii モジュールと RLocal::new を見つけ、次に libr::get と libr::set 周辺の呼び出し元とポインタに関する前提を調べます。API が null ポインタまたはその他の無効なポインタを受け取る可能性があるかを確認します。安全性の契約または可視性が明確になり、報告された未定義動作の経路に対処できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust
- 領域
- security
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100