Commit Graph

10689 Commits

Author SHA1 Message Date
Patrick Steinhardt
e0973bc0fc odb: verify hashes in read_prefix_1
While the function reading an object from the complete OID already
verifies OIDs, we do not yet do so for reading objects from a partial
OID. Do so when strict OID verification is enabled.
2017-04-28 14:10:37 +02:00
Patrick Steinhardt
141096202b odb: improve error handling in read_prefix_1
The read_prefix_1 function has several return statements springled
throughout the code. As we have to free memory upon getting an error,
the free code has to be repeated at every single retrun -- which it is
not, so we have a memory leak here.

Refactor the code to use the typical `goto out` pattern, which will free
data when an error has occurred. While we're at it, we can also improve
the error message thrown when multiple ambiguous prefixes are found. It
will now include the colliding prefixes.
2017-04-28 14:10:37 +02:00
Patrick Steinhardt
35079f507b odb: add option to turn off hash verification
Verifying hashsums of objects we are reading from the ODB may be costly
as we have to perform an additional hashsum calculation on the object.
Especially when reading large objects, the penalty can be as high as
35%, as can be seen when executing the equivalent of `git cat-file` with
and without verification enabled. To mitigate for this, we add a global
option for libgit2 which enables the developer to turn off the
verification, e.g. when he can be reasonably sure that the objects on
disk won't be corrupted.
2017-04-28 14:05:45 +02:00
Patrick Steinhardt
28a0741f1a odb: verify object hashes
The upstream git.git project verifies objects when looking them up from
disk. This avoids scenarios where objects have somehow become corrupt on
disk, e.g. due to hardware failures or bit flips. While our mantra is
usually to follow upstream behavior, we do not do so in this case, as we
never check hashes of objects we have just read from disk.

To fix this, we create a new error class `GIT_EMISMATCH` which denotes
that we have looked up an object with a hashsum mismatch. `odb_read_1`
will then, after having read the object from its backend, hash the
object and compare the resulting hash to the expected hash. If hashes do
not match, it will return an error.

This obviously introduces another computation of checksums and could
potentially impact performance. Note though that we usually perform I/O
operations directly before doing this computation, and as such the
actual overhead should be drowned out by I/O. Running our test suite
seems to confirm this guess. On a Linux system with best-of-five
timings, we had 21.592s with the check enabled and 21.590s with the
ckeck disabled. Note though that our test suite mostly contains very
small blobs only. It is expected that repositories with bigger blobs may
notice an increased hit by this check.

In addition to a new test, we also had to change the
odb::backend::nonrefreshing test suite, which now triggers a hashsum
mismatch when looking up the commit "deadbeef...". This is expected, as
the fake backend allocated inside of the test will return an empty
object for the OID "deadbeef...", which will obviously not hash back to
"deadbeef..." again. We can simply adjust the hash to equal the hash of
the empty object here to fix this test.
2017-04-28 14:05:45 +02:00
Patrick Steinhardt
d59dabe5cb tests: object: test looking up corrupted objects
We currently have no tests which check whether we fail reading corrupted
objects. Add one which modifies contents of an object stored on disk and
then tries to read the object.
2017-04-28 14:05:45 +02:00
Patrick Steinhardt
86c035526d tests: object: create sandbox
The object::lookup tests do use the "testrepo.git" repository in a
read-only way, so we do not set up the repository as a sandbox but
simply open it. But in a future commit, we will want to test looking up
objects which are corrupted in some way, which requires us to modify the
on-disk data. Doing this in a repository without creating the sandbox
will modify contents of our libgit2 repository, though.

Create the repository in a sandbox to avoid this.
2017-04-28 14:05:44 +02:00
Patrick Steinhardt
e29e802966 tests: odb: make hash of fake backend configurable
In the odb::backend::nonrefreshing test suite, we set up a fake backend
so that we are able to determine if backend functions are called
correctly. During the setup, we also parse an OID which is later on used
to read out the pseudo-object. While this procedure works right now, it
will create problems later when we implement hash verification for
looked up objects. The current OID ("deadbeef") will not match the hash
of contents we give back to the ODB layer and thus cannot be verified.

Make the hash configurable so that we can simply switch the returned for
single tests.
2017-04-28 14:05:44 +02:00
Edward Thomson
7df580fae6 Merge pull request #4191 from pks-t/pks/wt-ref-renames
Branch renames with worktrees
2017-04-28 11:58:49 +01:00
Russell Sim
b997fd2013 Updated change log to include CVE and bug numbers 2017-04-26 22:37:02 +02:00
Russell Sim
f74b4a9697 Updated symbols to fix Lintian error
Seems that I'll need to resurrect the old symbols file from 0.23 at
some point.
2017-04-26 20:49:54 +02:00
Russell Sim
d8c4cc8224 Add patch to fix spelling of error message
This is fixed upstream but lintian isn't happy
2017-04-26 20:31:06 +02:00
Russell Sim
cd6868bbfd Lintian fixes 2017-04-26 19:05:27 +02:00
Russell Sim
4794092bba Updated symbols file 2017-04-26 18:29:25 +02:00
Edward Thomson
6cf25a397e Merge pull request #4219 from pks-t/pks/socket-stream-addrinfo-loop
socket_stream: continue to next addrinfo on socket creation failure
2017-04-26 09:09:53 -07:00
Edward Thomson
cecd41fb64 Merge pull request #4217 from pks-t/pks/readonly-cfg-backend
Honor read-only flag when writing to config backends
2017-04-26 09:08:51 -07:00
Patrick Steinhardt
954e06a8d7 socket_stream: continue to next addrinfo on socket creation failure
When connecting to a remote via socket stream, we first use getaddrinfo
to obtain the possible connection methods followed by creating and
connecting the socket. But when creating the socket, we error out as
soon as we get an invalid socket instead of trying out other address
hints returned by addrinfo.

Fix this by continuing on invalid socket instead of returning an error.
This fixes connection establishment with musl libc.
2017-04-26 12:17:15 +02:00
Patrick Steinhardt
2a7086fa89 tests: config: verify functionality with read-only backends 2017-04-26 09:35:11 +02:00
Patrick Steinhardt
95f29fb35b config: skip r/o backends when writing
Configuration backends have a readonly-flag which is currently used to
distinguish configuration snapshots. But somewhat unexpectedly, we do
not use the flag to prevent writing to a readonly backend but happily
proceed to do so.

This commit modifies logic to also honor the readonly flag for
configuration setters. We will now traverse through all backends and
pick the first one which is not marked as read-only whenever we want to
write new configuration.
2017-04-26 09:35:11 +02:00
Russell Sim
9264488d40 Added patch to correctly assert the state of https feature 2017-04-25 23:29:38 +02:00
Edward Thomson
7f75eeaf99 Merge pull request #4215 from pks-t/pks/diff-stack-free
diff_parse: free object instead of its pointer
2017-04-25 07:10:33 -07:00
Patrick Steinhardt
64244131d0 config_file: add missing include for git_config_backend
The config_file.h header provides some inline declarations accessing the
`git_config_backend`, but misses its declaration. Add the missing
include for "git2/sys/config.h" to add it.
2017-04-25 13:28:21 +02:00
Patrick Steinhardt
417319cc86 tests: core::features: only check for HTTPS if it is supported 2017-04-25 10:15:59 +02:00
Patrick Steinhardt
a4de1ae389 cmake: define GIT_HTTPS when HTTPS is supported 2017-04-25 10:15:59 +02:00
Patrick Steinhardt
1cb30b1bb4 diff_parse: free object instead of its pointer
In e7330016a (diff_parse: check return value of `git_diff_init_options`,
2017-03-20), we've introduced an error check whether we're able to
correctly initialize the diff options. This simple commit actually
introduced a segfault in that we now try to free the pointer to the
allocated diff in an error case, instead of the allocated diff itself.
This commit fixes the issue.
2017-04-25 09:51:49 +02:00
Russell Sim
61b8cb7621 Removed super seeded timezone patch 2017-04-25 07:43:19 +02:00
Russell Sim
1a33904470 Update to 0.25.1 2017-04-25 07:32:15 +02:00
Russell Sim
0b9cba41f5 Imported Upstream version 0.25.1
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABCAAGBQJY/an5AAoJECKxCSrd3Efdh/MQALKI7SwNcRF6CtloZ8YlndHu
 JLNNfFoLsy4WtaHiikEeQqLGct3jcrEw6SbVSJt1GncaKPbYy2SKFEl9eKfqJ0zv
 IQmF3O1JESm+SawmNJqeHLWBeL3rbL4BomDfPA/9h6hUE0Jh/13nuqZKSS8bdiMv
 uIAfEgZSU0cvAaN7hEwiEsDWQ1bQqQ3mcPUF4hAK86e2E8J6LS5/VFdc6t/n9vlq
 827ec5umFRMSyjQa+MGDe5/slvD9ytKsCq/HJ2vSiIy9OTNLaOYsWYz45bsd6Oeu
 S5Y5k9WocShP0N7YId1/uWQUJhaPlk+Bf2MzXhtoepf8FgUxTFbPKexzYA/EXkiX
 nLLwo//8DyIfshRv9aQARfEScL3DpX1k5z5gIQbjZVXYWEOZx2lPE9rgZzjfpLaP
 dySXEEGJoJSL+EhD4gVf7a0hchWBVSBvXfrgGuXWK1tbFJLsr90LqCB9bRnn51i1
 n3dhIlaiVqLRFnGTJF/iRRahazgXDHxIHRnW5ALpIpkn/+Mpv/+4J5fyFpCw5Noe
 nN8PE10TAYHIkaYtQjHkkVE+bFNmXbtVP56HGgoWrmGNTySb7xZKCOMhtDI0Fp3f
 JFw8fuQjAeGcNUDVZicqxe4mPQPrFrTCZAY1FoLkJvP7EBuOV5SAkr/5sswIrP5B
 qJlgbMOV2aA2NELHGyhs
 =QuCY
 -----END PGP SIGNATURE-----

Merge tag 'upstream/0.25.1'

Imported Upstream version 0.25.1
2017-04-24 09:43:52 +02:00
Russell Sim
9c87194ea8 Imported Upstream version 0.25.1 2017-04-24 09:29:42 +02:00
Patrick Steinhardt
0d2f6824eb Merge pull request #4210 from pks-t/pks/misc-fixes
Misc fixes
2017-04-21 15:39:03 +02:00
Patrick Steinhardt
13c275aba5 tests: threads::diff: fix warning for unused variable
The threads::diff test suite has a static variable `_retries`, which is
used on Windows platforms only. As it is unused on other systems, the
compiler throws a warning there. Fix the warning by wrapping the
declaration in an ifdef.
2017-04-21 07:49:08 +00:00
Patrick Steinhardt
f4d1592c2f global: fix typo in git_libgit2_init description 2017-04-21 07:48:30 +00:00
Carlos Martín Nieto
8d89e40961 Merge pull request #4192 from libgit2/ethomson/win32_posix
Refactor some of the win32 POSIX emulation
2017-04-17 17:19:03 +02:00
Edward Thomson
86536c7e45 win32: remediation not cleanup
The `remediation` function is run in the retry loop in order to attempt
to fix any problems that the prior run encountered.  There is nothing
"cleaned up".  Clarify the name.
2017-04-17 15:40:03 +01:00
Carlos Martín Nieto
5c76096046 transport: provide a getter for the proxy options
As with the callbacks, third-party implementations of smart subtransports cannot
reach into the opaque struct and thus cannot know what options the user set.

Add a getter for these options to copy the proxy options into something external
implementors can use.
2017-04-17 13:03:03 +02:00
Edward Thomson
f9d3b0d05f Merge pull request #4201 from pks-t/pks/fileops-fd-leak
fileops: fix leaking fd in `mmap_ro_file`
2017-04-12 09:21:26 +01:00
Patrick Steinhardt
38b6e70027 fileops: fix leaking fd in mmap_ro_file
When the `git_futils_mmap_ro_file` function encounters an error after
the file has been opened, it will do a simple returns. Instead, we
should close the opened file descriptor to avoid a leak. This commit
fixes the issue.
2017-04-12 08:09:08 +02:00
Edward Thomson
d476d024d0 Merge pull request #4196 from pks-t/pks/filter-segfault
filter: only close filter if it's been initialized correctly
2017-04-11 19:18:05 +01:00
Edward Thomson
a5781e2a18 Merge pull request #4195 from pks-t/pks/openssl-1.1
Fix building against OpenSSL v1.1
2017-04-11 19:17:11 +01:00
Edward Thomson
1262963add Merge pull request #4198 from pks-t/pks/git-compat
README: document our relation to changes in upstream
2017-04-11 19:10:28 +01:00
Patrick Steinhardt
19a04f67cd README: document our relation to changes in upstream
libgit2 is a mere consumer of changes which are trickling down from the
upstream git.git project. This commit documents the ramifications caused
by this relation.
2017-04-11 07:22:02 +02:00
Patrick Steinhardt
78b8f0392c tests: fix indentation in checkout::head::with_index_only_tree 2017-04-10 12:44:19 +02:00
Patrick Steinhardt
88520151fd openssl_stream: use new initialization function on OpenSSL version >=1.1
Previous to OpenSSL version 1.1, the user had to initialize at least the error
strings as well as the SSL algorithms by himself. OpenSSL version 1.1 instead
provides a new function `OPENSSL_init_ssl`, which handles initialization of all
subsystems. As the new API call will by default load error strings and
initialize the SSL algorithms, we can safely replace these calls when compiling
against version 1.1 or later.

This fixes a compiler error when compiling against OpenSSL version 1.1 which has
been built without stubs for deprecated syntax.
2017-04-10 11:29:07 +02:00
Patrick Steinhardt
29081c2fd4 openssl_stream: remove locking initialization on OpenSSL version >=1.1
Up to version 1.0, OpenSSL required us to provide a callback which implements
a locking mechanism. Due to problems in the API design though this mechanism was
inherently broken, especially regarding that the locking callback cannot report
errors in an obvious way. Due to this shortcoming, the locking initialization
has been completely removed in OpenSSL version 1.1. As the library has also been
refactored to not make any use of these callback functions, we can safely remove
all initialization of the locking subsystem if compiling against OpenSSL version
1.1 or higher.

This fixes a compilation error when compiling against OpenSSL version 1.1 which
has been built without stubs for deprecated syntax.
2017-04-10 11:29:07 +02:00
Patrick Steinhardt
cf07db2f1b filter: only close filter if it's been initialized correctly
In the function `git_filter_list_stream_data`, we initialize, write and
subesquently close the stream which should receive content processed by
the filter. While we skip writing to the stream if its initialization
failed, we still try to close it unconditionally -- even if the
initialization failed, where the stream might not be set at all, leading
us to segfault.

Semantics in this code is not really clear. The function handling the
same logic for files instead of data seems to do the right thing here in
only closing the stream when initialization succeeded. When stepping
back a bit, this is only reasonable: if a stream cannot be initialized,
the caller would not expect it to be closed again. So actually, both
callers of `stream_list_init` fail to do so. The data streaming function
will always close the stream and the file streaming function will not
close the stream if writing to it has failed.

The fix is thus two-fold:

- callers of `stream_list_init` now close the stream iff it has been
  initialized
- `stream_list_init` now closes the lastly initialized stream if
  the current stream in the chain failed to initialize

Add a test which segfaulted previous to these changes.
2017-04-07 16:34:47 +02:00
Edward Thomson
e572b63121 Merge pull request #4183 from pks-t/pks/coverity
Coverity
2017-04-07 09:03:56 +01:00
Edward Thomson
44998cdb9a Merge pull request #4193 from pks-t/pks/libdir
pkgconfig: fix handling of prefixes containing whitespaces
2017-04-07 09:02:54 +01:00
Patrick Steinhardt
22436f2945 pkgconfig: fix handling of prefixes containing whitespaces
Our libgit2.pc.in file is quoting the `libdir` variable in our declared
"Libs:" line. The intention is to handle whitespaces here, but pkgconfig
already does so by automatically escaping whitespace with backslashes.
The correct thing to do is to instead quote the prefix, as this is the
one which is being substituted by CMake upon installation. As both
libdir and includedir will be expanded to "${prefix}/lib" and
"${prefix}/include", respectively, pkgconfig will also correctly escape
whitespaces.

Note that this will actually break when a user manually wants to
override libdir and includedir with a path containing whitespace. But
actually, this cannot be helped, as always quoting these variables will
actuall break the common case of being prefixed with "${prefix}". So we
just bail out here and declare this as unsupported out of the box.
2017-04-05 14:46:23 +02:00
Patrick Steinhardt
2a485dabc0 refs: update worktree HEADs when renaming branches
Whenever we rename a branch, we update the repository's symbolic HEAD
reference if it currently points to the branch that is to be renamed.
But with the introduction of worktrees, we also have to iterate over all
HEADs of linked worktrees to adjust them. Do so.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
38fc5ab0a2 branch: use foreach_head to see if a branch is checked out
Previously, we have extracted the logic to find and iterate over all
HEADs of a repository. Use this function in `git_branch_is_checked_out`.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
74511aa204 repository: add function to iterate over all HEADs
While we already provide functions to get the current repository's HEAD,
it is quite involved to iterate over HEADs of both the repository and
all linked work trees. This commit implements a function
`git_repository_foreach_head`, which accepts a callback which is then
called for all HEAD files.
2017-04-05 13:50:38 +02:00