Skip to content

Commit d65d197

Browse files
committed
Auto merge of #11381 - ehuss:beta-fix-safe-directory, r=weihanglo
[beta-1.66] Backport fix for git2 safe-directory disable Beta backports: * #11366 — fix git2 safe-directory disable * #11332 — fix semver documentation for change in non_exhaustive * #11335 — Clean more aggressively in CI
2 parents 7e484fc + 4d1d2b2 commit d65d197

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

.github/workflows/main.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ jobs:
8080

8181
# Deny warnings on CI to avoid warnings getting into the codebase.
8282
- run: cargo test --features 'deny-warnings'
83+
# The testsuite generates a huge amount of data, and fetch-smoke-test was
84+
# running out of disk space.
85+
- name: Clear test output
86+
run: |
87+
df -h
88+
rm -rf target/tmp
89+
df -h
8390
- name: Check operability of rustc invocation with argfile
8491
env:
8592
__CARGO_TEST_FORCE_ARGFILE: 1
@@ -111,7 +118,7 @@ jobs:
111118
cargo check --manifest-path benches/capture/Cargo.toml
112119
# The testsuite generates a huge amount of data, and fetch-smoke-test was
113120
# running out of disk space.
114-
- name: Clear test output
121+
- name: Clear benchmark output
115122
run: |
116123
df -h
117124
rm -rf target/tmp

src/bin/cargo/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Run with 'cargo -Z [FLAG] [COMMAND]'",
149149
}
150150
};
151151
config_configure(config, &expanded_args, subcommand_args, global_args)?;
152-
super::init_git_transports(config);
152+
super::init_git(config);
153153

154154
execute_subcommand(config, cmd, subcommand_args)
155155
}

src/bin/cargo/main.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,38 @@ fn search_directories(config: &Config) -> Vec<PathBuf> {
246246
path_dirs
247247
}
248248

249+
/// Initialize libgit2.
250+
fn init_git(config: &Config) {
251+
// Disabling the owner validation in git can, in theory, lead to code execution
252+
// vulnerabilities. However, libgit2 does not launch executables, which is the foundation of
253+
// the original security issue. Meanwhile, issues with refusing to load git repos in
254+
// `CARGO_HOME` for example will likely be very frustrating for users. So, we disable the
255+
// validation.
256+
//
257+
// For further discussion of Cargo's current interactions with git, see
258+
//
259+
// https://github.com/rust-lang/rfcs/pull/3279
260+
//
261+
// and in particular the subsection on "Git support".
262+
//
263+
// Note that we only disable this when Cargo is run as a binary. If Cargo is used as a library,
264+
// this code won't be invoked. Instead, developers will need to explicitly disable the
265+
// validation in their code. This is inconvenient, but won't accidentally open consuming
266+
// applications up to security issues if they use git2 to open repositories elsewhere in their
267+
// code.
268+
unsafe {
269+
git2::opts::set_verify_owner_validation(false)
270+
.expect("set_verify_owner_validation should never fail");
271+
}
272+
273+
init_git_transports(config);
274+
}
275+
276+
/// Configure libgit2 to use libcurl if necessary.
277+
///
278+
/// If the user has a non-default network configuration, then libgit2 will be
279+
/// configured to use libcurl instead of the built-in networking support so
280+
/// that those configuration settings can be used.
249281
fn init_git_transports(config: &Config) {
250282
// Only use a custom transport if any HTTP options are specified,
251283
// such as proxies or custom certificate authorities. The custom
@@ -274,27 +306,4 @@ fn init_git_transports(config: &Config) {
274306
unsafe {
275307
git2_curl::register(handle);
276308
}
277-
278-
// Disabling the owner validation in git can, in theory, lead to code execution
279-
// vulnerabilities. However, libgit2 does not launch executables, which is the foundation of
280-
// the original security issue. Meanwhile, issues with refusing to load git repos in
281-
// `CARGO_HOME` for example will likely be very frustrating for users. So, we disable the
282-
// validation.
283-
//
284-
// For further discussion of Cargo's current interactions with git, see
285-
//
286-
// https://github.com/rust-lang/rfcs/pull/3279
287-
//
288-
// and in particular the subsection on "Git support".
289-
//
290-
// Note that we only disable this when Cargo is run as a binary. If Cargo is used as a library,
291-
// this code won't be invoked. Instead, developers will need to explicitly disable the
292-
// validation in their code. This is inconvenient, but won't accidentally open consuming
293-
// applications up to security issues if they use git2 to open repositories elsewhere in their
294-
// code.
295-
unsafe {
296-
if git2::opts::set_verify_owner_validation(false).is_err() {
297-
return;
298-
}
299-
}
300309
}

src/doc/src/reference/semver.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub enum E {
391391
fn main() {
392392
use updated_crate::E;
393393
let x = E::Variant1;
394-
match x { // Error: `Variant2` not covered
394+
match x { // Error: `E::Variant2` not covered
395395
E::Variant1 => {}
396396
}
397397
}

0 commit comments

Comments
 (0)