Skip to content

Commit efa63de

Browse files
committed
update libgit2 to 1.4.3
CVE 2022-24765
1 parent 31d3ff0 commit efa63de

File tree

10 files changed

+52
-21
lines changed

10 files changed

+52
-21
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git2"
3-
version = "0.14.3"
3+
version = "0.15.0"
44
authors = ["Josh Triplett <[email protected]>", "Alex Crichton <[email protected]>"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"
@@ -20,7 +20,7 @@ url = "2.0"
2020
bitflags = "1.1.0"
2121
libc = "0.2"
2222
log = "0.4.8"
23-
libgit2-sys = { path = "libgit2-sys", version = "0.13.3" }
23+
libgit2-sys = { path = "libgit2-sys", version = "0.14.0+1.4.3" }
2424

2525
[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
2626
openssl-sys = { version = "0.9.0", optional = true }

git2-curl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ edition = "2018"
1616
curl = "0.4.33"
1717
url = "2.0"
1818
log = "0.4"
19-
git2 = { path = "..", version = "0.14", default-features = false }
19+
git2 = { path = "..", version = "0.15", default-features = false }
2020

2121
[dev-dependencies]
2222
civet = "0.11"

git2-curl/tests/all.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const PORT: u16 = 7848;
99
fn main() {
1010
unsafe {
1111
git2_curl::register(curl::easy::Easy::new());
12+
13+
// In tests on Windows, the repository is created in a temporary directory.
14+
// The ownership check will fail in these directories, so we need to disable it in tests.
15+
#[cfg(windows)]
16+
let _ = git2::opts::set_verify_owner_validation(false);
1217
}
1318

1419
// Spin up a server for git-http-backend

libgit2-sys/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libgit2-sys"
3-
version = "0.13.3+1.4.2"
3+
version = "0.14.0+1.4.3"
44
authors = ["Josh Triplett <[email protected]>", "Alex Crichton <[email protected]>"]
55
links = "git2"
66
build = "build.rs"

libgit2-sys/build.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
if try_to_use_system_libgit2 {
1616
let mut cfg = pkg_config::Config::new();
1717
if let Ok(lib) = cfg
18-
.range_version("1.4.0".."1.5.0")
18+
.range_version("1.4.3".."1.5.0")
1919
.print_system_libs(false)
2020
.probe("libgit2")
2121
{
@@ -45,21 +45,20 @@ fn main() {
4545
cp_r("libgit2/include", &include);
4646

4747
cfg.include(&include)
48-
.include("libgit2/src/libgit2")
48+
.include("libgit2/src")
4949
.include("libgit2/src/util")
5050
.out_dir(dst.join("build"))
5151
.warnings(false);
5252

5353
// Include all cross-platform C files
54-
add_c_files(&mut cfg, "libgit2/src/libgit2");
55-
add_c_files(&mut cfg, "libgit2/src/util");
56-
add_c_files(&mut cfg, "libgit2/src/libgit2/xdiff");
54+
add_c_files(&mut cfg, "libgit2/src");
55+
add_c_files(&mut cfg, "libgit2/src/xdiff");
5756

5857
// These are activated by features, but they're all unconditionally always
5958
// compiled apparently and have internal #define's to make sure they're
6059
// compiled correctly.
61-
add_c_files(&mut cfg, "libgit2/src/libgit2/transports");
62-
add_c_files(&mut cfg, "libgit2/src/libgit2/streams");
60+
add_c_files(&mut cfg, "libgit2/src/transports");
61+
add_c_files(&mut cfg, "libgit2/src/streams");
6362

6463
// Always use bundled http-parser for now
6564
cfg.include("libgit2/deps/http-parser")
@@ -88,11 +87,11 @@ fn main() {
8887
// when when COMPILE_PCRE8 is not defined, which is the default.
8988
add_c_files(&mut cfg, "libgit2/deps/pcre");
9089

91-
cfg.file("libgit2/src/util/allocators/failalloc.c");
92-
cfg.file("libgit2/src/util/allocators/stdalloc.c");
90+
cfg.file("libgit2/src/allocators/failalloc.c");
91+
cfg.file("libgit2/src/allocators/stdalloc.c");
9392

9493
if windows {
95-
add_c_files(&mut cfg, "libgit2/src/util/win32");
94+
add_c_files(&mut cfg, "libgit2/src/win32");
9695
cfg.define("STRSAFE_NO_DEPRECATE", None);
9796
cfg.define("WIN32", None);
9897
cfg.define("_WIN32_WINNT", Some("0x0600"));
@@ -104,7 +103,7 @@ fn main() {
104103
cfg.define("__USE_MINGW_ANSI_STDIO", "1");
105104
}
106105
} else {
107-
add_c_files(&mut cfg, "libgit2/src/util/unix");
106+
add_c_files(&mut cfg, "libgit2/src/unix");
108107
cfg.flag("-fvisibility=hidden");
109108
}
110109
if target.contains("solaris") || target.contains("illumos") {
@@ -162,9 +161,9 @@ fn main() {
162161
cfg.define("SHA1DC_NO_STANDARD_INCLUDES", "1");
163162
cfg.define("SHA1DC_CUSTOM_INCLUDE_SHA1_C", "\"common.h\"");
164163
cfg.define("SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C", "\"common.h\"");
165-
cfg.file("libgit2/src/util/hash/sha1/collisiondetect.c");
166-
cfg.file("libgit2/src/util/hash/sha1/sha1dc/sha1.c");
167-
cfg.file("libgit2/src/util/hash/sha1/sha1dc/ubc_check.c");
164+
cfg.file("libgit2/src/hash/sha1/collisiondetect.c");
165+
cfg.file("libgit2/src/hash/sha1/sha1dc/sha1.c");
166+
cfg.file("libgit2/src/hash/sha1/sha1dc/ubc_check.c");
168167

169168
if let Some(path) = env::var_os("DEP_Z_INCLUDE") {
170169
cfg.include(path);

libgit2-sys/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![doc(html_root_url = "https://docs.rs/libgit2-sys/0.13")]
1+
#![doc(html_root_url = "https://docs.rs/libgit2-sys/0.14")]
22
#![allow(non_camel_case_types, unused_extern_crates)]
33

44
// This is required to link libz when libssh2-sys is not included.
@@ -1894,6 +1894,8 @@ git_enum! {
18941894
GIT_OPT_SET_ODB_LOOSE_PRIORITY,
18951895
GIT_OPT_GET_EXTENSIONS,
18961896
GIT_OPT_SET_EXTENSIONS,
1897+
GIT_OPT_GET_OWNER_VALIDATION,
1898+
GIT_OPT_SET_OWNER_VALIDATION,
18971899
}
18981900
}
18991901

libgit2-sys/libgit2

Submodule libgit2 updated 887 files

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
//! source `Repository`, to ensure that they do not outlive the repository
6666
//! itself.
6767
68-
#![doc(html_root_url = "https://docs.rs/git2/0.14")]
68+
#![doc(html_root_url = "https://docs.rs/git2/0.15")]
6969
#![allow(trivial_numeric_casts, trivial_casts)]
7070
#![deny(missing_docs)]
7171
#![warn(rust_2018_idioms)]

src/opts.rs

+13
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ where
178178
Ok(())
179179
}
180180

181+
/// Set wheter or not to verify ownership before performing a repository.
182+
/// Enabled by default, but disabling this can lead to code execution vulnerabilities.
183+
pub unsafe fn set_verify_owner_validation(enabled: bool) -> Result<(), Error> {
184+
let error = raw::git_libgit2_opts(
185+
raw::GIT_OPT_SET_OWNER_VALIDATION as libc::c_int,
186+
enabled as libc::c_int,
187+
);
188+
// This function cannot actually fail, but the function has an error return
189+
// for other options that can.
190+
debug_assert!(error >= 0);
191+
Ok(())
192+
}
193+
181194
#[cfg(test)]
182195
mod test {
183196
use super::*;

src/test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ use std::io;
33
use std::path::{Path, PathBuf};
44
#[cfg(unix)]
55
use std::ptr;
6+
#[cfg(windows)]
7+
use std::sync::Once;
68
use tempfile::TempDir;
79
use url::Url;
810

911
use crate::{Branch, Oid, Repository, RepositoryInitOptions};
1012

13+
/// In tests on Windows, the repository is created in a temporary directory.
14+
/// The ownership check will fail in these directories, so we need to disable it in tests.
15+
#[cfg(windows)]
16+
static DISABLE_OWNER_CHECK: Once = Once::new();
17+
1118
macro_rules! t {
1219
($e:expr) => {
1320
match $e {
@@ -18,6 +25,11 @@ macro_rules! t {
1825
}
1926

2027
pub fn repo_init() -> (TempDir, Repository) {
28+
#[cfg(windows)]
29+
DISABLE_OWNER_CHECK.call_once(|| unsafe {
30+
let _ = crate::opts::set_verify_owner_validation(false);
31+
});
32+
2133
let td = TempDir::new().unwrap();
2234
let mut opts = RepositoryInitOptions::new();
2335
opts.initial_head("main");

0 commit comments

Comments
 (0)