-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined Behavior/Segfault when using git2 < 0.14.0 with libgit2 >= 1.4.0 #813
Comments
This is a bug in libgit2-sys, I tried to explain what's going on and what could be done in the issue that reported this problem when there was a ABI break with 1.3.0: #746 (comment) Now that there has been another ABI break I think it's pretty clear that the version of libgit2 doesn't indicate ABI stability, and the build script should be changed to an exact version. If possible this should be backported to past releases so there's a chance people stop getting segfaults from other crates that depend on older versions of libgit2-rs. |
See also [1][2]. Fixes #307. [1] rust-lang/git2-rs#813 [2] rust-lang/cargo#10446
libgit2 does not have a stable ABI across minor versions, as has been demonstrated in the last few minor releases, see rust-lang#813 and rust-lang#746. This pain is primarily suffered by users of rolling release distros, because they tend to get a new libgit2 version before the authors of libraries release versions that pull in the new libgit2-sys version which works with the new binary. This patch means that going forward, users don't need to rush to upgrade their version of libgit2-sys or suffer errors/UB in the meantime. If the system version changes, they will just start using the vendored version which has been tested against the bindings.
Is there a workaround available currently for this issue? I tried enabling the |
If you run The |
I'll try to reduce the binary to a minimal reproduction.
This project is used to manage the services on my server and spawns multiple sub-processes so it may not be easiest one to debug the issue. I am compiling on Arch Linux 64 bit. I have |
Seems like system libgit2 is being dynamically loaded with |
I will see what I can find. |
I ran this smaller program with Running it with gdb, I get the following output:
Sorry for the big wall of text, I am not very familiar with |
This is a null pointer dereference. ASan reports this:
I suspect this is unrelated to the ABI problem. |
libgit2 does not have a stable ABI across minor versions, as has been demonstrated in the last few minor releases, see #813 and #746. This pain is primarily suffered by users of rolling release distros, because they tend to get a new libgit2 version before the authors of libraries release versions that pull in the new libgit2-sys version which works with the new binary. This patch means that going forward, users don't need to rush to upgrade their version of libgit2-sys or suffer errors/UB in the meantime. If the system version changes, they will just start using the vendored version which has been tested against the bindings.
I believe this has now been addressed in current git2, which ensures that it depends on a sufficiently recent libgit2. |
A new field was added to
git_fetch_options
in v1.4.0 of libgit2, which makes this call unsound on the condition that any version ofgit2
below v0.14.0 is used andlibgit2.so.1.4
is linked, which has happened already on bleeding edge distributions.This has already happened to me and apparently a few others on killercup/cargo-edit#641, and in my investigation I found the issue to be due to a segfault in
validate_custom_headers
, asfollow_redirects
is incorrectly "initialized" withcustom_headers
'sgit_strarray
while the actualcustom_headers
points to junk data past the end of the struct, causinggit_strarray
'scount
to be uninitialized memory/random junk, which causes the code to dereferencestrings
which also points to random junk.I'm not entirely sure how to fix this gracefully. Maybe issue an advisory to all crates using
git2
to upgrade to 0.14.0? Wouldn't it cause the same issue in reverse to those who still uselibgit2.so.1.3
?The text was updated successfully, but these errors were encountered: