Commit Graph

9892 Commits

Author SHA1 Message Date
Carlos Martín Nieto
7da4c429ea refdb: adjust the threading tests to what we promise
We say it's going to work if you use a different repository in each
thread. Let's do precisely that in our code instead of hoping re-using
the refdb is going to work.

This test does fail currently, surfacing existing bugs.
2016-11-14 11:25:58 +01:00
Patrick Steinhardt
0f31609611 repository: do not interpret all files as gitlinks in discovery
When trying to find a discovery, we walk up the directory
structure checking if there is a ".git" file or directory and, if
so, check its validity. But in the case that we've got a ".git"
file, we do not want to unconditionally assume that the file is
in fact a ".git" file and treat it as such, as we would error out
if it is not.

Fix the issue by only treating a file as a gitlink file if it
ends with "/.git". This allows users of the function to discover
a repository by handing in any path contained inside of a git
repository.
2016-11-14 10:53:08 +01:00
Patrick Steinhardt
4dbaf3cd62 test: discover: fix indentation 2016-11-14 10:53:08 +01:00
Patrick Steinhardt
5242c42488 test: discover: split up monolithic test into smaller ones 2016-11-14 10:53:08 +01:00
Patrick Steinhardt
07afeb23ae test: discover: pass constants to ensure_repository_discover 2016-11-14 10:53:08 +01:00
Patrick Steinhardt
2382b0f877 test: discover: move layout creation into test initializer 2016-11-14 10:53:08 +01:00
Carlos Martín Nieto
e1c14335d8 Merge pull request #4002 from pks-t/pks/giterr-format
giterr format
2016-11-14 10:48:57 +01:00
Carlos Martín Nieto
cc5966b071 Merge pull request #3983 from pks-t/pks/smart-early-eof
transports: smart: abort on early end of stream
2016-11-14 10:39:45 +01:00
Carlos Martín Nieto
eb71490ac2 Merge pull request #3985 from libgit2/cmn/threading-update
Update THREADING for OpenSSL 1.1
2016-11-14 10:19:30 +01:00
Patrick Steinhardt
b81fe7c96d path: pass string instead of git_buf to giterr_set 2016-11-14 10:07:55 +01:00
Patrick Steinhardt
90a934a521 checkout: pass string instead of git_buf to giterr_set 2016-11-14 10:07:55 +01:00
Patrick Steinhardt
901434b00f common: cast precision specifiers to int 2016-11-14 10:07:55 +01:00
Patrick Steinhardt
c77a55a917 common: use PRIuZ for size_t in giterr_set calls 2016-11-14 10:05:59 +01:00
Patrick Steinhardt
8effd26f59 common: mark printf-style formatting for giterr_set 2016-11-14 09:54:08 +01:00
Patrick Steinhardt
2d20551642 Merge pull request #3992 from joshtriplett/env-namespace
git_repository_open_ext: fix handling of $GIT_NAMESPACE
2016-11-14 09:38:44 +01:00
Patrick Steinhardt
19981467ea Merge pull request #4001 from pks-t/pks/fileops-docs-typo
fileops: fix typos in `git_futils_creat_locked{,with_path}`
2016-11-14 09:31:31 +01:00
Patrick Steinhardt
7b3f49f0c9 fileops: fix typos in git_futils_creat_locked{,with_path} 2016-11-14 09:31:07 +01:00
Josh Triplett
c9e967a1b4 git_repository_open_ext: fix handling of $GIT_NAMESPACE
The existing code would set a namespace of "" (empty string) with
GIT_NAMESPACE unset.  In a repository where refs/heads/namespaces/
exists, that can produce incorrect results.  Detect that case and avoid
setting the namespace at all.

Since that makes the last assignment to error conditional, and the
previous assignment can potentially get GIT_ENOTFOUND, set error to 0
explicitly to prevent the call from incorrectly failing with
GIT_ENOTFOUND.
2016-11-11 14:15:06 -08:00
Patrick Steinhardt
b7822050c9 Merge pull request #3993 from alexcrichton/fix-fault 2016-11-11 11:25:39 +01:00
Alex Crichton
5ca75fd52c curl_stream: check for -1 after CURLINFO_LASTSOCKET
We're recently trying to upgrade to the current master of libgit2
in Cargo but we're unfortunately hitting a segfault in one of our
tests. This particular test is just a small smoke test that https
works (e.g. it's configured in libgit2). It attempts to clone
from a URL which simply immediately drops connections after
they're accepted (e.g. terminate abnormally). We expect to see a
standard error from libgit2 but unfortunately we're seeing a
segfault.

This segfault is happening inside of the `wait_for` function of
`curl_stream.c` at the line `FD_SET(fd, &errfd)` because `fd` is
-1. This ends up doing an out-of-bounds array access that faults
the program. I tracked back to where this -1 came from to the
line here (returned by `CURLINFO_LASTSOCKET`) and added a check
to return an error.
2016-11-11 11:22:15 +01:00
Patrick Steinhardt
5fe5557e8a Merge pull request #3974 from libgit2/pks/synchronize-shutdown
global: synchronize initialization and shutdown with pthreads
2016-11-04 18:18:46 +01:00
Patrick Steinhardt
6e2fab9ede Merge pull request #3977 from jfultz/fix-forced-branch-creation-on-bare-repo 2016-11-04 18:14:00 +01:00
John Fultz
f9793884a3 branch: fix forced branch creation on HEAD of a bare repo
The code correctly detects that forced creation of a branch on a
nonbare repo should not be able to overwrite a branch which is
the HEAD reference.  But there's no reason to prevent this on
a bare repo, and in fact, git allows this.  I.e.,

   git branch -f master new_sha

works on a bare repo with HEAD set to master.  This change fixes
that problem, and updates tests so that, for this case, both the
bare and nonbare cases are checked for correct behavior.
2016-11-04 18:12:35 +01:00
Carlos Martín Nieto
f7d316ed7a THREADING: OpenSSL 1.1 is thead-safe, rework some paragraphs 2016-11-04 10:11:59 +01:00
Carlos Martín Nieto
86bbaaa1a6 THREADING: update cURL thread safety link 2016-11-02 17:06:15 +01:00
Carlos Martín Nieto
7175222ce6 Merge pull request #3960 from ignatenkobrain/openssl-1.1.0
add support for OpenSSL 1.1.0 for BIO filter
2016-11-02 14:50:59 +01:00
Carlos Martín Nieto
3b832a085b openssl: include OpenSSL headers only when we're buliding against it
We need to include the initialisation and construction functions in all
backend, so we include this header when building against SecureTransport
and WinHTTP as well.
2016-11-02 13:11:31 +01:00
Carlos Martín Nieto
d2451fedfa Merge pull request #3984 from pks-t/pks/pack-find-offset-race
pack: fix race in pack_entry_find_offset
2016-11-02 13:05:35 +01:00
Carlos Martín Nieto
2f3adf9513 openssl: use ASN1_STRING_get0_data when compiling against 1.1
For older versions we can fall back on the deprecated ASN1_STRING_data.
2016-11-02 13:02:13 +01:00
Carlos Martín Nieto
f15eedb3a3 openssl: recreate the OpenSSL 1.1 BIO interface for older versions
We want to program against the interface, so recreate it when we compile
against pre-1.1 versions.
2016-11-02 13:00:30 +01:00
Patrick Steinhardt
0cf15e39f3 pack: fix race in pack_entry_find_offset
In `pack_entry_find_offset`, we try to find the offset of a
certain object in the pack file. To do so, we first assert if the
packfile has already been opened and open it if not. Opening the
packfile is guarded with a mutex, so concurrent access to this is
in fact safe.

What is not thread-safe though is our calculation of offsets
inside the packfile. Assume two threads calling
`pack_entry_find_offset` at the same time. We first calculate the
offset and index location and only then determine if the pack has
already been opened. If so, we re-calculate the offset and index
address.

Now the case for two threads: thread 1 first calculates the
addresses and is subsequently suspended. The second thread will
now call `pack_index_open` and initialize the pack file,
calculating its addresses correctly. When the first thread is
resumed now, he'll see that the pack file has already been
initialized and will happily proceed with the addresses it has
already calculated before the check. As the pack file was not
initialized before, these addresses are bogus.

Fix the issue by only calculating the addresses after having
checked if the pack file is open.
2016-11-02 12:23:12 +01:00
Patrick Steinhardt
62494bf234 transports: smart: abort receiving packets on end of stream
When trying to receive packets from the remote, we loop until
either an error distinct to `GIT_EBUFS` occurs or until we
successfully parsed the packet. This does not honor the case
where we are looping over an already closed socket which has no
more data, leaving us in an infinite loop if we got a bogus
packet size or if the remote hang up.

Fix the issue by returning `GIT_EEOF` when we cannot read data
from the socket anymore.
2016-11-02 09:42:56 +01:00
Patrick Steinhardt
61530c497d transports: smart: abort ref announcement on early end of stream
When reading a server's reference announcements via the smart
protocol, we expect the server to send multiple flushes before
the protocol is finished. If we fail to receive new data from the
socket, we will only return an end of stream error if we have not
seen any flush yet.

This logic is flawed in that we may run into an infinite loop
when receiving a server's reference announcement with a bogus
flush packet. E.g. assume the last flushing package is changed to
not be '0000' but instead any other value. In this case, we will
still await one more flush package and ignore the fact that we
are not receiving any data from the socket, causing an infinite
loop.

Fix the issue by always returning `GIT_EEOF` if the socket
indicates an end of stream.
2016-11-02 09:41:39 +01:00
Patrick Steinhardt
19001ca7ba Merge pull request #3976 from pks-t/pks/pqueue-null-deref
pqueue: resolve possible NULL pointer dereference
2016-11-02 09:23:53 +01:00
Patrick Steinhardt
1c33ecc445 tests: core: test deinitialization and concurrent initialization
Exercise the logic surrounding deinitialization of the libgit2
library as well as repeated concurrent de- and reinitialization.
This tries to catch races and makes sure that it is possible to
reinitialize libgit2 multiple times.

After deinitializing libgit2, we have to make sure to setup
options required for testing. Currently, this only includes
setting up the configuration search path again. Before, this has
been set up once in `tests/main.c`.
2016-11-02 08:53:52 +01:00
Patrick Steinhardt
038f0e1b4c global: reset global state on shutdown without threading
When threading is not enabled for libgit2, we keep global state
in a simple static variable. When libgit2 is shut down, we clean
up the global state by freeing the global state's dynamically
allocated memory. When libgit2 is built with threading, we
additionally free the thread-local storage and thus completely
remove the global state. In a non-threaded build, though, we
simply leave the global state as-is, which may result in an error
upon reinitializing libgit2.

Fix the issue by zeroing out the variable on a shutdown, thus
returning it to its initial state.
2016-11-02 08:53:52 +01:00
Etienne Samson
8d400c096a transaction: fix documentation 2016-11-01 17:49:07 +01:00
Etienne Samson
788fcdb8e3 remote: fix documentation and indent 2016-11-01 17:46:57 +01:00
Etienne Samson
2adac91008 remote: unused function typedef 2016-11-01 17:46:37 +01:00
Etienne Samson
8d2784d570 describe: fix documentation 2016-11-01 17:46:20 +01:00
Patrick Steinhardt
6502398f96 proxy: fix typo in documentation 2016-11-01 16:55:16 +01:00
Patrick Steinhardt
59c6c2860a global: synchronize initialization and shutdown with pthreads
When trying to initialize and tear down global data structures
from different threads at once with `git_libgit2_init` and
`git_libgit2_shutdown`, we race around initializing data. While
we use `pthread_once` to assert that we only initilize data a
single time, we actually reset the `pthread_once_t` on the last
call to `git_libgit2_shutdown`. As resetting this variable is not
synchronized with other threads trying to access it, this is
actually racy when one thread tries to do a complete shutdown of
libgit2 while another thread tries to initialize it.

Fix the issue by creating a mutex which synchronizes `init_once`
and the library shutdown.
2016-11-01 14:30:47 +01:00
Carlos Martín Nieto
41ad9ebfad Merge pull request #3975 from pks-t/pks/ci-improvements
CI Improvements
2016-11-01 09:59:17 +01:00
Edward Thomson
a051ee31f2 Merge pull request #3978 from pks-t/pks/doc-improvements
Small documentation improvements
2016-10-31 16:02:43 +00:00
Patrick Steinhardt
0334bf4b24 travis: do not allow valgrind failures
Our valgrind jobs haven't been failing for several builds by now.
This indicates that our tests are sufficiently stable when
running under valgrind. As such, any failures reported by
valgrind become interesting to us and shouldn't be ignored when
causing a build to fail.

Remove the valgrind job from the list of allowed failures.
2016-10-31 16:01:10 +01:00
Patrick Steinhardt
18c18e3df8 coverity: check for Coverity token only if necessary
When running a Coverity build, we have to provide an
authentication token in order to proof that we are actually
allowed to run analysis in the name of a certain project. As this
token should be secret, it is only set on the main repository, so
when we were requested to run the Coverity script on another
repository we do error out. But in fact we do also error out if
the Coverity analysis should _not_ be run if there is no
authentication token provided.

Fix the issue by only checking for the authentication token after
determining if analysis is indeed requested.
2016-10-31 16:01:10 +01:00
Patrick Steinhardt
dc98cb28db openssl_stream: fix typo 2016-10-31 13:50:23 +01:00
Patrick Steinhardt
59665db3b3 PROJECTS: consistently quote directories 2016-10-31 13:50:13 +01:00
Patrick Steinhardt
ea9ea6ac4a Documentation: fix small typos 2016-10-31 13:49:52 +01:00
Patrick Steinhardt
95fa38802f pqueue: resolve possible NULL pointer dereference
The `git_pqueue` struct allows being fixed in its total number of
entries. In this case, we simply throw away items that are
inserted into the priority queue by examining wether the new item
to be inserted has a higher priority than the previous smallest
one.

This feature somewhat contradicts our pqueue implementation in
that it is allowed to not have a comparison function. In fact, we
also fail to check if the comparison function is actually set in
the case where we add a new item into a fully filled fixed-size
pqueue.

As we cannot determine which item is the smallest item in absence
of a comparison function, we fix the `NULL` pointer dereference
by simply dropping all new items which are about to be inserted
into a full fixed-size pqueue.
2016-10-28 16:19:24 +02:00