Skip to content
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

remote-curl: unbreak http.extraHeader with custom allocators #453

Conversation

dscho
Copy link
Member

@dscho dscho commented Nov 5, 2019

This is one of those bugs that can cost entire days of work.

The symptom of this bug is that git -c http.extraheader push ... will fail frequently in Git for Windows v2.24.0, but not always. When it fails, though, it will cause a segmentation fault in git remote-https while calling http_cleanup() and leave no visual indication of that problem, the only indication of a problem will be the exit code of the caller (in this instance, git push will fail with exit code 1).

In my tests during the pre-release period, I pushed many a time, it probably failed a lot, in the way indicated above, and due to the absence of any error message, I failed to realize that there was a problem in the first place.

Fun side note: this bug haunted me for the best part of this past Monday, when I tried to get Git for Windows v2.24.0 out the door. Large parts of Git for Windows' release management are scripted, and that script failed, claiming to have been unsuccessful in pushing the tag v2.24.0.windows.1, just after printing a message to the extent that the tag is already up to date (except in the first attempt, when it reported to have been successful in pushing the tag). My attempts to fix the release script were doomed to fail because the root cause was not a bug in the script, but the bug fixed in this patch.

Changes since v1:

  • The patch was completely redone: instead of moving the call to curl_global_init() (which would have broken support for http.sslbackend), this iteration instead replaces the usage of cURL's slist in the config handling by using Git's own string_list.

Cc: Carlo Marcelo Arenas Belón carenas@gmail.com

@dscho
Copy link
Member Author

dscho commented Nov 5, 2019

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 5, 2019

dscho added a commit to git-for-windows/build-extra that referenced this pull request Nov 5, 2019
Using `http.extraHeader` [no longer results in spurious
crashes](gitgitgadget/git#453).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
http.c Outdated Show resolved Hide resolved
In 93b980e (http: use xmalloc with cURL, 2019-08-15), we started to
ask cURL to use `xmalloc()`, and if compiled with nedmalloc, that means
implicitly a different allocator than the system one.

Which means that all of cURL's allocations and releases now _need_ to
use that allocator.

However, the `http_options()` function used `slist_append()` to add any
configured extra HTTP header(s) _before_ asking cURL to use `xmalloc()`,
and `http_cleanup()` would release them _afterwards_, i.e. in the
presence of custom allocators, cURL would attempt to use the wrong
allocator to release the memory.

A naïve attempt at fixing this would move the call to
`curl_global_init()` _before_ the config is parsed (i.e. before that
call to `slist_append()`).

However, that does work, as we _also_ parse the config setting
`http.sslbackend` and if found, call `curl_global_sslset()` which *must*
be called before `curl_global_init()`, for details see:
https://curl.haxx.se/libcurl/c/curl_global_sslset.html

So let's instead make the config parsing entirely independent from
cURL's data structures. Incidentally, this deletes two more lines than
it introduces, which is nice.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho force-pushed the fix-curl-xmalloc-regression branch from d47a2aa to 3168ba2 Compare November 6, 2019 09:29
@dscho
Copy link
Member Author

dscho commented Nov 6, 2019

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 6, 2019

http.c Show resolved Hide resolved
http.c Show resolved Hide resolved
@gitgitgadget

This comment has been minimized.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 6, 2019

This branch is now known as cb/curl-use-xmalloc.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 6, 2019

This patch series was integrated into pu via git@94ada8c.

@gitgitgadget gitgitgadget bot added the pu label Nov 6, 2019
@ghost
Copy link

ghost commented Nov 7, 2019

And I almost updated, but decided to wait a few more days, appreciate all the bug hunting!

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 2, 2019

This patch series was integrated into pu via git@bad5ed3.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 2, 2019

This patch series was integrated into next via git@bad5ed3.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 2, 2019

This patch series was integrated into master via git@bad5ed3.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 2, 2019

Closed via bad5ed3.

@dscho dscho deleted the fix-curl-xmalloc-regression branch December 2, 2019 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant