Commit Graph

12969 Commits

Author SHA1 Message Date
Patrick Steinhardt
0119e57df0 streams: openssl: switch approach to silence Valgrind errors
As OpenSSL loves using uninitialized bytes as another source of entropy,
we need to mark them as defined so that Valgrind won't complain about
use of these bytes. Traditionally, we've been using the macro
`VALGRIND_MAKE_MEM_DEFINED` provided by Valgrind, but starting with
OpenSSL 1.1 the code doesn't compile anymore due to `struct SSL` having
become opaque. As such, we also can't set it as defined anymore, as we
have no way of knowing its size.

Let's change gears instead by just swapping out the allocator functions
of OpenSSL with our own ones. The twist is that instead of calling
`malloc`, we just call `calloc` to have the bytes initialized
automatically. Next to soothing Valgrind, this approach has the benefit
of being completely agnostic of the memory sanitizer and is neatly
contained at a single place.

Note that we shouldn't do this for non-Valgrind builds. As we cannot
set up memory functions for a given SSL context, only, we need to swap
them at a global context. Furthermore, as it's possible to call
`OPENSSL_set_mem_functions` once only, we'd prevent users of libgit2 to
set up their own allocators.
2020-02-11 12:01:54 +01:00
Patrick Steinhardt
877054f39c cmake: consolidate Valgrind option
OpenSSL doesn't initialize bytes on purpose in order to generate
additional entropy. Valgrind isn't too happy about that though, causing
it to generate warninings about various issues regarding use of
uninitialized bytes.

We traditionally had some infrastructure to silence these errors in our
OpenSSL stream implementation, where we invoke the Valgrind macro
`VALGRIND_MAKE_MEMDEFINED` in various callbacks that we provide to
OpenSSL. Naturally, we only include these instructions if a preprocessor
define "VALGRIND" is set, and that in turn is only set if passing
"-DVALGRIND" to CMake. We do that in our usual Azure pipelines, but we
in fact forgot to do this in our nightly build. As a result, we get a
slew of warnings for these nightly builds, but not for our normal
builds.

To fix this, we could just add "-DVALGRIND" to our nightly builds. But
starting with commit d827b11b6 (tests: execute leak checker via CTest
directly, 2019-06-28), we do have a secondary variable that directs
whether we want to use memory sanitizers for our builds. As such, every
user wishing to use Valgrind for our tests needs to pass both options
"VALGRIND" and "USE_LEAK_CHECKER", which is cumbersome and error prone,
as can be seen by our own builds.

Instead, let's consolidate this into a single option, removing the old
"-DVALGRIND" one. Instead, let's just add the preprocessor directive if
USE_LEAK_CHECKER equals "valgrind" and remove "-DVALGRIND" from our own
pipelines.
2020-02-11 10:27:18 +01:00
Edward Thomson
ee3307a183 Merge pull request #5392 from pks-t/pks/ci-warnings
azure: fix misleading messages printed to stderr being
2020-02-08 17:34:53 +00:00
Edward Thomson
6a61a418c0 Merge pull request #5393 from pks-t/pks/tests-iterator-missing-ref
tests: iterator: fix iterator expecting too few items
2020-02-08 17:32:51 +00:00
Patrick Steinhardt
26b71d605c tests: iterator: fix iterator expecting too few items
The testcase iterator::workdir::filesystem_gunk sets up quite a lot of
directories, which is why it only runs in case GITTEST_INVASIVE_SPEED is
set in the environment. Because we do not run our default CI with this
variable, we didn't notice commit 852c83ee4 (refs: refuse to delete
HEAD, 2020-01-15) breaking the test as it introduced a new reference to
the "testrepo" repository.

Fix the oversight by increasing the number of expected iterator items.
2020-02-07 14:36:10 +01:00
Patrick Steinhardt
49bb4237cb azure: test: silence termination message when killing git-daemon(1)
In order to properly tear down the test environment, we will kill
git-daemon(1) if we've exercised it. As git-daemon(1) is spawned as a
background process, it is still owned by the shell and thus killing it
later on will print a termination message to the shell's stderr, causing
Azure to report it as an error.

Fix this by disowning the background process.
2020-02-07 14:04:07 +01:00
Patrick Steinhardt
fb03f02aa1 azure: docker: avoid re-creating libgit2 home directory
The Docker entrypoint currently creates the libgit2 user with "useradd
--create-home". As we start the Docker container with two volumes
pointing into "/home/libgit2/", the home directory will already exist.
While useradd(1) copes with this just fine, it will print error messages
to stderr which end up as failures in our Azure pipelines.

Fix this by simply removing the "--create-home" parameter.
2020-02-07 13:56:36 +01:00
Patrick Steinhardt
52cb4040f3 azure: test: silence curl to not cause Azure to trop
Without the "--silent" parameter, curl will print a progress meter to
stderr. Azure has the nice feature of interpreting any output to stderr
as errors with a big red warning towards the end of the build. Let's
thus silence curl to not generate any misleading messages.
2020-02-07 13:56:33 +01:00
Patrick Steinhardt
a3ec07d737 azure: docker: pipe downloaded archives into tar(1) directly
When building dependencies for our Docker images, we first download the
sources to disk first, unpack them and finally remove the archive again.
This can be sped up by piping the downloading archive into tar(1)
directly to parallelize both tasks. Furthermore, let's silence curl(1)
to not print to status information to stderr, which tends to be
interpreted as errors by Azure Pipelines.
2020-02-07 13:34:18 +01:00
Patrick Steinhardt
03ac24b119 Merge pull request #5387 from pks-t/pks/transport-http-custom-headers
transports: http: fix custom headers not being applied
2020-02-07 11:36:36 +01:00
Patrick Steinhardt
65ac33aeb1 Merge pull request #5382 from libgit2/pks/azure-coverity
azure: fix Coverity pipeline
2020-02-07 11:18:24 +01:00
Patrick Steinhardt
46228d86f8 transports: http: fix custom headers not being applied
In commit b9c5b15a7 (http: use the new httpclient, 2019-12-22), the HTTP
code got refactored to extract a generic HTTP client that operates
independently of the Git protocol. Part of refactoring was the creation
of a new `git_http_request` struct that encapsulates the generation of
requests. Our Git-specific HTTP transport was converted to use that in
`generate_request`, but during the process we forgot to set up custom
headers for the `git_http_request` and as a result we do not send out
these headers anymore.

Fix the issue by correctly setting up the request's custom headers and
add a test to verify we correctly send them.
2020-02-07 11:13:43 +01:00
Patrick Steinhardt
86c54cc8a8 azure: coverity: fix Coverity builds due to various issues
There's several issues with our Coverity builds, like e.g. missing wget
in our containers. Simplify our Coverity pipeline and fix these issues.
2020-02-07 10:41:18 +01:00
Patrick Steinhardt
ccffea6bfa azure: coverity: convert to use self-built containers
Back in commit 5a6740e7f (azure: build Docker images as part of the
pipeline, 2019-08-02), we have converted our pipelines to use self-built
Docker images to ease making changes to our Dockerfiles. The commit
didn't adjust our Coverity pipeline, though, so let's do this now.
2020-02-07 10:41:18 +01:00
Patrick Steinhardt
b4eb0282a7 azure: coverity: fix invalid syntax for Docker image
In commit bbc0b20bd (azure: fix Coverity's build due to wrong container
name, 2019-08-02), Coverity builds were fixed to use the correct
container names. Unfortunately, the "fix" completely broke our Coverity
builds due to using wrong syntax for the Docker task. Let's fix this by
using "imageName" instead of the Docker dict.
2020-02-07 10:41:18 +01:00
Patrick Steinhardt
bd6b1c4157 Merge pull request #5381 from pks-t/pks/tests-flaky-proxy
azure: tests: re-run flaky proxy tests
2020-02-06 06:14:20 +01:00
Patrick Steinhardt
c51bd2f20f azure: tests: reset FAILED status if flaky re-run succeeds
While we already do have logic to re-run flaky tests, the FAILED
variable currently does not get reset to "0". As a result, successful
reruns will still cause the test to be registered as failed.

Fix this by resetting the variable accordingly.
2020-02-04 12:17:40 +01:00
Patrick Steinhardt
b33ad76473 azure: tests: re-run flaky proxy tests
The proxy tests regularly fail in our CI environment. Unfortunately,
this is expected due to the network layer. Thus, let's re-try the proxy
tests up to five times in case they fail.
2020-02-04 11:26:57 +01:00
Edward Thomson
559751714b Merge pull request #5373 from pks-t/pks/fetchhead-strip-creds
fetchhead: strip credentials from remote URL
2020-02-01 09:03:00 +00:00
Patrick Steinhardt
93a9044ff6 fetchhead: strip credentials from remote URL
If fetching from an anonymous remote via its URL, then the URL gets
written into the FETCH_HEAD reference. This is mainly done to give
valuable context to some commands, like for example git-merge(1), which
will put the URL into the generated MERGE_MSG. As a result, what gets
written into FETCH_HEAD may become public in some cases. This is
especially important considering that URLs may contain credentials, e.g.
when cloning 'https://foo:bar@example.com/repo' we persist the complete
URL into FETCH_HEAD and put it without any kind of sanitization into the
MERGE_MSG. This is obviously bad, as your login data has now just leaked
as soon as you do git-push(1).

When writing the URL into FETCH_HEAD, upstream git does strip
credentials first. Let's do the same by trying to parse the remote URL
as a "real" URL, removing any credentials and then re-formatting the
URL. In case this fails, e.g. when it's a file path or not a valid URL,
we just fall back to using the URL as-is without any sanitization. Add
tests to verify our behaviour.
2020-01-31 15:25:47 +01:00
Edward Thomson
a1bff63bf1 Merge pull request #5375 from pks-t/pks/test-ci
azure-pipelines: properly expand negotiate passwords
2020-01-31 13:44:47 +00:00
Patrick Steinhardt
7aa99dd347 azure-pipelines: properly expand negotiate passwords
To allow testing against a Kerberos instance, we have added variables
for the Kerberos password to allow authentication against LIBGIT2.ORG in
commit e5fb5fe5a (ci: perform SPNEGO tests, 2019-10-20). To set up the
password, we assign

    "GITTEST_NEGOTIATE_PASSWORD=$(GITTEST_NEGOTIATE_PASSWORD)"

in the environmentVariables section which is then passed through to a
template. As the template does build-time expansion of the environment
variables, it will expand the above line verbosely, and due to the
envVar section not doing any further expansion the password variable
will end up with the value "$(GITTEST_NEGOTIATE_PASSWORD)" in the
container's environment.

Fix this fixed by doing expansion of GITTEST_NEGOTIATE_PASSWORD at
build-time, as well.
2020-01-31 12:51:51 +01:00
Patrick Steinhardt
aa4cd778b9 Merge pull request #5336 from libgit2/ethomson/credtype
cred: change enum to git_credential_t and GIT_CREDENTIAL_*
2020-01-30 10:40:44 +01:00
Patrick Steinhardt
f9b41a6600 Merge pull request #5371 from ayush-1506/julia_link
Update link to libgit2 Julia language binding
2020-01-30 10:30:12 +01:00
ayush-1506
103a76b424 Update link to Julia libgit2 2020-01-30 17:58:43 +11:00
Edward Thomson
3f54ba8b61 credential: change git_cred to git_credential
We avoid abbreviations where possible; rename git_cred to
git_credential.

In addition, we have standardized on a trailing `_t` for enum types,
instead of using "type" in the name.  So `git_credtype_t` has become
`git_credential_t` and its members have become `GIT_CREDENTIAL` instead
of `GIT_CREDTYPE`.

Finally, the source and header files have been renamed to `credential`
instead of `cred`.

Keep previous name and values as deprecated, and include the new header
files from the previous ones.
2020-01-26 18:39:41 +00:00
Edward Thomson
4383ab402a Merge pull request #5365 from libgit2/ethomson/no_void
Return int from non-free functions
2020-01-24 15:32:09 -06:00
Edward Thomson
4cae9e712c git_libgit2_version: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
f78f6bd597 error functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
4b331f020e revwalk functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
82050fa1be mempack functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
a3126a72d2 repository functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
cb43274a6b index functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
82154e586c remote functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
3351506aa8 tree functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
2e8c3b0b18 oid functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
9893d376ee git_attr_cache_flush: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
4460bf40c9 Merge pull request #5286 from libgit2/ethomson/gssapi
HTTP: Support Apache-based servers with Negotiate
2020-01-24 11:08:44 -06:00
Edward Thomson
e9cef7c4b1 http: introduce GIT_ERROR_HTTP
Disambiguate between general network problems and HTTP problems in error
codes.
2020-01-24 10:39:56 -06:00
Edward Thomson
7fd9b3f597 ci: add NTLM tests
Download poxygit, a debugging git server, and clone from it using NTLM,
both IIS-style (with connection affinity) and Apache-style ("broken",
requiring constant reauthentication).
2020-01-24 10:39:56 -06:00
Edward Thomson
29762e4089 httpclient: use defines for status codes 2020-01-24 10:39:56 -06:00
Edward Thomson
3e9ee04f11 trace: compare against an int value
When tracing is disabled, don't let `git_trace__level` return a void,
since that can't be compared against.
2020-01-24 10:39:56 -06:00
Edward Thomson
76fd406a75 http: send probe packets
When we're authenticating with a connection-based authentication scheme
(NTLM, Negotiate), we need to make sure that we're still connected
between the initial GET where we did the authentication and the POST
that we're about to send.  Our keep-alive session may have not kept
alive, but more likely, some servers do not authenticate the entire
keep-alive connection and may have "forgotten" that we were
authenticated, namely Apache and nginx.

Send a "probe" packet, that is an HTTP POST request to the upload-pack
or receive-pack endpoint, that consists of an empty git pkt ("0000").
If we're authenticated, we'll get a 200 back.  If we're not, we'll get a
401 back, and then we'll resend that probe packet with the first step of
our authentication (asking to start authentication with the given
scheme).  We expect _yet another_ 401 back, with the authentication
challenge.

Finally, we will send our authentication response with the actual POST
data.  This will allow us to authenticate without draining the POST data
in the initial request that gets us a 401.
2020-01-24 10:39:56 -06:00
Edward Thomson
b9c5b15a79 http: use the new httpclient
Untangle the notion of the http transport from the actual http
implementation.  The http transport now uses the httpclient.
2020-01-24 10:39:51 -06:00
Edward Thomson
bf55facf15 tests: allow users to use expect/continue 2020-01-24 10:16:36 -06:00
Edward Thomson
7372573b5f httpclient: support expect/continue
Allow users to opt-in to expect/continue handling when sending a POST
and we're authenticated with a "connection-based" authentication
mechanism like NTLM or Negotiate.

If the response is a 100, return to the caller (to allow them to post
their body).  If the response is *not* a 100, buffer the response for
the caller.

HTTP expect/continue is generally safe, but some legacy servers
have not implemented it correctly.  Require it to be opt-in.
2020-01-24 10:16:36 -06:00
Edward Thomson
6c21c989a3 httpclient: support CONNECT proxies
Fully support HTTP proxies, in particular CONNECT proxies, that allow us
to speak TLS through a proxy.
2020-01-24 10:16:36 -06:00
Edward Thomson
6b2088363f httpclient: handle chunked responses
Detect responses that are sent with Transfer-Encoding: chunked, and
record that information so that we can consume the entire message body.
2020-01-24 10:16:36 -06:00
Edward Thomson
6a095679c8 httpclient: support authentication
Store the last-seen credential challenges (eg, all the
'WWW-Authenticate' headers in a response message).  Given some
credentials, find the best (first) challenge whose mechanism supports
these credentials.  (eg, 'Basic' supports username/password credentials,
'Negotiate' supports default credentials).

Set up an authentication context for this mechanism and these
credentials.  Continue exchanging challenge/responses until we're
authenticated.
2020-01-24 10:16:36 -06:00
Edward Thomson
0e39a8faf9 net: free the url's query component 2020-01-24 10:16:36 -06:00