# `Repository::workdir()`, `namespace()` and `get_attr()` return borrows that another `&self` call frees (use-after-free in safe code)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 15/100
Hướng nghiên cứu
The three unsound getters are workdir(), namespace()/namespace_bytes() and get_attr()/get_attr_bytes() in src/repo.rs, with the freeing setters at about lines 529 and 560-579. Start by running the reproducer under AddressSanitizer to confirm each use-after-free. Done means the getters return owned values or the signatures change so a freeing call cannot be made while the borrow is alive, and the maintainers agree on the breaking-change approach first.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Three Repository getters return a &Path/&str that points at a C string owned by libgit2 and
is tied only to &self. In each case another method that also takes &self makes libgit2 free
that string, so the borrow checker accepts code that reads freed memory:
workdir()(src/repo.rs:515), freed byset_workdir(&self, ..)(:529);namespace()/namespace_bytes()(:545,:555), freed byset_namespace,
set_namespace_bytesandremove_namespace(:560-:579);get_attr()/get_attr_bytes()(:1109,:1130): the value points into libgit2's cached
.gitattributesrules, which the next attribute lookup frees if the file changed on disk.
#![forbid(unsafe_code)]
use git2::{AttrCheckFlags, Repository};
use std::path::Path;
fn main() {
let dir = std::env::temp_dir().join("git2-borrowed-strings");
let repo = Repository::init(&dir).unwrap();
match std::env::args().nth(1).as_deref() {
Some("namespace") => {
repo.set_namespace("first").unwrap();
let ns = repo.namespace().unwrap().unwrap(); // borrows repo->namespace
repo.set_namespace("second").unwrap(); // frees it
println!("{ns}");
}
Some("attr") => {
let (attrs, file) = (dir.join(".gitattributes"), Path::new("a.txt"));
std::fs::write(&attrs, "*.txt foo=first-value\n").unwrap();
let flags = AttrCheckFlags::default();
let value = repo.get_attr(file, "foo", flags).unwrap().unwrap(); // points into the attr cache
std::fs::write(&attrs, "*.txt foo=second\n").unwrap();
let _ = repo.get_attr(file, "foo", flags); // reloads the file, frees the old rules
println!("{value}");
}
_ => {
let workdir = repo.workdir().unwrap(); // borrows repo->workdir
repo.set_workdir(&dir.join(".git"), false).unwrap(); // frees it
println!("{}", workdir.display());
}
}
}
Run against git2-rs b9d59b6 (main) with the vendored libgit2 1.9.7, under AddressSanitizer, with
no argument (trimmed):
ERROR: AddressSanitizer: heap-use-after-free
READ of size 1 at 0x76897a1084d0 thread T0
#15 workdir_freed_by_set_workdir::main src/main.rs:32:13
0x76897a1084d0 is located 0 bytes inside of 32-byte region
freed by thread T0 here:
#3 git_repository_set_workdir libgit2/src/libgit2/repository.c:3302:3
#4 <git2::repo::Repository>::set_workdir src/call.rs:13:39
#5 workdir_freed_by_set_workdir::main src/main.rs:31:18
With namespace the freeing frame is git_repository_set_namespace (repository.c:1719); with
attr it is git_attr_cache__get (attrcache.c:280) called from git_attr_get.
Possible fix
For workdir and namespace, make the setters take &mut self (as submodule_set_url does), or
return owned values. For get_attr, &mut self would not help because the second lookup is itself
a getter; returning an owned value would. All are breaking changes.
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.
- Ngôn ngữ chính
- Rust
- Star
- 2.1k
- Fork
- 470
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/git2-rs
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 messageCó thể đã có người làm @shivampwm2020 đã nhận 43 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/git2-rs
Issue tương tự
-
bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows microphone listing treats words in a device name as DirectShow labelsCó thể đã có người làm @Sujal-chaudhary đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
clipy-recorder/clipy#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
nightly-cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
max-sixty/worktrunk#4939 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursĐang mởflaky
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
stacks-network/stacks-core#7918 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày