Skip to content

shadow-rs does not report error with git "dubious ownership" fatal error #177

@taoky

Description

@taoky

Since CVE-2022-24765, new git version adds an ownership check functionality, and if git owner != current uid, git command would report such error:

# git status
fatal: detected dubious ownership in repository at '/example'
To add an exception for this directory, call:

	git config --global --add safe.directory /example

However, shadow-rs would silently ignore the error, and returns empty values for git-related consts.

Reproduce:

  1. Initialize an empty project, with a non-root user and files in "Setup" in shadow-rs README (shadow-rs 0.32.0)

  2. Add println!("{}", build::CLAP_LONG_VERSION); in main()

  3. git init and git commit -a

  4. Build with same non-root user:

    0.1.0
    branch:master
    commit_hash:d423f07a
    build_time:2024-08-21 17:02:35 +08:00
    build_env:rustc 1.80.1 (3f5fd8dd4 2024-08-06),stable-x86_64-unknown-linux-gnu
    
  5. Use su to change user to root (Don't use sudo as git would try check this with SUDO_USER env). git status in root would report this fatal error.

  6. cargo clean and build with root:

    0.1.0
    branch:
    commit_hash:
    build_time:2024-08-21 17:05:18 +08:00
    build_env:rustc 1.80.1 (3f5fd8dd4 2024-08-06),stable-x86_64-unknown-linux-gnu
    

This could make it hard to debug when building Rust projects with Docker (by default it uses root inside container), especially in CI environment (to be frankly this spent me an afternoon to find the bug).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions