[BUG] Heap buffer overflow: calling `Repository::find_submodule("/")` → 1-byte read before heap buffer

Abierto
#1,359 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
64/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
git, rust
Área
backend, security

Línea de trabajo

The report points to Repository::find_submodule and libgit2’s git_submodule__lookup_with_cache; start by tracing how the / path is handled in that lookup. Reproduce with the provided Rust program and AddressSanitizer command. Done when the call no longer triggers the reported heap-buffer-overflow and the regression is covered by a test.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Can be triggered on the latest commit b9d59b6 (git2, vendored-libgit2 feature), from rust safe code (#![forbid(unsafe_code)]).

Summary

Running the program below prints the following and aborts with a heap-buffer-overflow:

calling find_submodule("/")
==ERROR: AddressSanitizer: heap-buffer-overflow  READ of size 1
  #0 git_submodule__lookup_with_cache
  #1 git_submodule_lookup
  #2 <git2::repo::Repository>::find_submodule
  #3 10r::main

is located 1 bytes before 8-byte region
allocated by thread T0 here:
  #0 realloc
  #6 git_str_puts
  #7 git_submodule__lookup_with_cache
  #8 git_submodule_lookup
  #9 <git2::repo::Repository>::find_submodule

Calling repo.find_submodule("/") on the initialized repository allocates an 8-byte buffer during find_submodule and reads 1 byte before the start of that allocation.

Reproduce

Cargo.toml:

[dependencies]
git2 = { version = "0.21.0", default-features = false, features = ["vendored-libgit2"] }

src/main.rs:

#![forbid(unsafe_code)]
use git2::Repository;
use std::path::Path;

fn main() {
    let dir = Path::new("tmp/git2-10");
    let _ = std::fs::remove_dir_all(dir);
    let repo = Repository::init(dir).expect("Repository::init");
    eprintln!("calling find_submodule(\"/\")");
    let r = repo.find_submodule("/");
    eprintln!("find_submodule -> {:?}", r.err());
    let _ = std::fs::remove_dir_all(dir);
}
CFLAGS="-fsanitize=address" RUSTFLAGS="-Zsanitizer=address" \
  cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-gnu
Lenguaje dominante
Rust
Estrellas
2.1k
Forks
470
Merge medio
2 d 17 h
PR fusionados (30 d)
18

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/git2-rs

Todos los issues de rust-lang/git2-rs

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.