# `Repository::config()` returns a `Config` that can outlive the repository its file backend points to (use-after-free in safe code)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 15/100
調査の方向性
Start at Repository::config() in src/repo.rs (around line 1081), which returns a Config with no lifetime tying it to the repository. The ASan trace shows the stale pointer is read in libgit2's config_file.c during config_file_refresh when an includeIf "gitdir:" section is re-evaluated. Done means the lifetime or ownership design is settled and the reproducer no longer touches freed memory, which is a breaking API decision that needs maintainer input first.
索引モデルが issue の本文から書いたものです。
説明
Repository::config() (src/repo.rs:1081) returns a Config, which has no lifetime parameter.
git_repository_config hands out the repository's own config object with its reference count
incremented, but that object's file backends keep a plain pointer to the repository
(config_file.c:109). libgit2 uses the pointer when it re-reads a changed config file that has an
includeIf "gitdir:..." section. So after the Repository is dropped, a read through the Config
can dereference the freed repository:
#![forbid(unsafe_code)]
use git2::Repository;
fn main() {
let dir = std::env::temp_dir().join(format!("config-includeif-{}", std::process::id()));
let repo = Repository::init(&dir).unwrap();
let config_path = dir.join(".git/config");
let mut text = std::fs::read_to_string(&config_path).unwrap();
text.push_str("[includeIf \"gitdir:/nonexistent/\"]\n\tpath = other.inc\n");
std::fs::write(&config_path, &text).unwrap();
let config = repo.config().unwrap(); // no lifetime ties it to `repo`
drop(repo); // frees the git_repository the file backend points to
// Change the file so that the next read refreshes it.
text.push_str("[user]\n\tname = someone\n");
std::fs::write(&config_path, &text).unwrap();
println!("{:?}", config.get_string("user.name")); // re-parses with b->repo
let _ = std::fs::remove_dir_all(&dir);
}
Run against git2-rs b9d59b6 (main) with the vendored libgit2 1.9.7, under AddressSanitizer
(trimmed):
ERROR: AddressSanitizer: heap-use-after-free
READ of size 8 at 0x73f1a7406ee0 thread T0
#0 git_repository_path libgit2/src/libgit2/repository.c:3224:15
#3 do_match_gitdir libgit2/src/libgit2/config_file.c:629:15
#5 parse_conditional_include libgit2/src/libgit2/config_file.c:748:16
#10 config_file_refresh libgit2/src/libgit2/config_file.c:244:15
#11 config_file_get libgit2/src/libgit2/config_file.c:349:39
#15 <git2::config::Config>::get_string src/call.rs:13:39
#16 config_outlives_repository_includeif::main src/main.rs:24:29
0x73f1a7406ee0 is located 160 bytes inside of 400-byte region
freed by thread T0 here:
#3 git_repository_free libgit2/src/libgit2/repository.c:195:2
#4 <git2::repo::Repository as core::ops::drop::Drop>::drop src/repo.rs:3492:18
Repository::index() documents that its Index becomes detached when the repository is dropped;
config() has no such note, and for the config the stale pointer is still used.
Possible fix
Tie the handle to the repository, e.g. Config<'repo> or a wrapper type returned by
Repository::config(), as Odb<'repo> and Refdb<'repo> already are. This is a breaking change.
Found by Crustify, an experimental
UB/soundness auditing agent developed at UC Berkeley and running on Claude Opus 5.5, then
manually reviewed and independently reproduced.
- 主要言語
- Rust
- スター
- 2.1k
- フォーク
- 470
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 18
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/git2-rs のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 message対応中かも @shivampwm2020 が 43 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
rust-lang/git2-rs の issue をすべて見る
似ている issue
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Windows microphone listing treats words in a device name as DirectShow labels対応中かも @Sujal-chaudhary が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
clipy-recorder/clipy#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
nightly-cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
max-sixty/worktrunk#4939 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursオープンflaky
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
stacks-network/stacks-core#7918 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信