Commit Graph

12759 Commits

Author SHA1 Message Date
Edward Thomson
6df3ec4a52 valgrind: suppress libssh2_rsa_sha1_sign leaks 2019-11-24 16:49:35 +11:00
Edward Thomson
c64b7aaa6e ci: build our own valgrind
The valgrind in the PPA is broken and ignores `--exit-errorcode`.
Build and install our own.
2019-11-24 16:49:35 +11:00
Edward Thomson
7adc32d525 valgrind: suppress kexinit leaks 2019-11-24 16:49:35 +11:00
Edward Thomson
fd831275ce ci: build shared libssh2 2019-11-24 16:49:35 +11:00
Edward Thomson
8480788492 ci: break dockerfile into stages
Use a multi-stage docker build so that we can cache early stages and not
need to download the apt-provided dependencies during every build (when
only later stages change).
2019-11-24 16:49:35 +11:00
Edward Thomson
7a3d04dc62 ci: don't delete the apt cache
Deleting the apt cache can be helpful for reducing the size of a
container, but since we don't push it anywhere, it only hinders our
ability to debug problems while working on the container.  Keep it.
2019-11-24 16:49:35 +11:00
Edward Thomson
f592c737bf ci: don't install libssh2 since we build it 2019-11-24 16:49:35 +11:00
Edward Thomson
5dc1be8d54 valgrind: suppress uninitialized reads in libcrypto
libcrypto will read uninitialized memory as entropy.  Suppress warnings
from this behavior.
2019-11-23 11:28:02 +11:00
Edward Thomson
767990e9d9 ci: show distribution information
The lsb-release command is missing on our images; just show the
information from the file instead of relying on it.
2019-11-23 11:25:44 +11:00
Edward Thomson
91ba65af8f ci: provide a default for xcode generator
Provide a sane default for `CMAKE_GENERATOR` in the build script so that
it can be invoked without having to set that in the environment.
2019-11-23 10:58:38 +11:00
Edward Thomson
47dd665a62 Merge pull request #5303 from pks-t/pks/patch-path-in-body-only
patch_parse: use paths from "---"/"+++" lines for binary patches
2019-11-16 15:21:56 -08:00
Edward Thomson
cb6bc6f25b Merge pull request #5285 from pcpthm/winhttp-308
Follow 308 redirect in WinHTTP transport
2019-11-16 15:17:54 -08:00
Edward Thomson
541b8fc5f0 Merge pull request #5302 from tiennou/fix/p_lstat-errno
fileops: correct error return on p_lstat failures when mkdir
2019-11-16 15:12:52 -08:00
Patrick Steinhardt
de7659ccc8 patch_parse: use paths from "---"/"+++" lines for binary patches
For some patches, it is not possible to derive the old and new file
paths from the patch header's first line, most importantly when they
contain spaces. In such a case, we derive both paths from the "---" and
"+++" lines, which allow for non-ambiguous parsing. We fail to use these
paths when parsing binary patches without data, though, as we always
expect the header paths to be filled in.

Fix this by using the "---"/"+++" paths by default and only fall back to
header paths if they aren't set. If neither of those paths are set, we
just return an error. Add two tests to verify this behaviour, one of
which would have previously caused a segfault.
2019-11-10 18:54:01 +01:00
Etienne Samson
0c2b02061e fileops: correct error return on p_lstat failures when mkdir
IIRC I got a strange return once from lstat, which translated in a weird
error class/message being reported. As a safety measure, enforce a -1 return in
that case.
2019-11-09 09:41:52 +01:00
Edward Thomson
01ea911b9e Merge pull request #5299 from pks-t/pks/config-mem-snapshots
config_mem: implement support for snapshots
2019-11-06 06:04:55 -05:00
Edward Thomson
a3d8a43755 Merge pull request #5298 from pks-t/pks/patch-whitespace-only-paths
patch_parse: fix segfault when header path contains whitespace only
2019-11-06 06:04:37 -05:00
Patrick Steinhardt
146e5bf7b1 config_mem: implement support for snapshots
Similar as in commit dadbb33b6 (Fix crash if snapshotting a
config_snapshot, 2019-11-01), let's implement snapshots for in-memory
configuration entries. As this deletes more code than it adds, it
doesn't make any sense to not allow for this and allows users to treat
config backends mostly the same.
2019-11-06 07:29:13 +01:00
Patrick Steinhardt
de543e297d patch_parse: fix segfault when header path contains whitespace only
When parsing header paths from a patch, we reject any patches with empty
paths as malformed patches. We perform the check whether a path is empty
before sanitizing it, though, which may lead to a path becoming empty
after the check, e.g. if we have trimmed whitespace. This may lead to a
segfault later when any part of our patching logic actually references
such a path, which may then be a `NULL` pointer.

Fix the issue by performing the check after sanitizing. Add tests to
catch the issue as they would have produced a segfault previosuly.
2019-11-05 22:50:41 +01:00
Patrick Steinhardt
5d773a1833 Merge pull request #5282 from pks-t/pks/config-file-iterator-race
config_file: fix race when creating an iterator
2019-11-05 13:04:10 +01:00
Patrick Steinhardt
56b203a5e0 config_file: keep reference to config entries when creating iterator
When creating a configuration file iterator, then we first refresh the
backend and then afterwards duplicate all refreshed configuration
entries into the iterator in order to avoid seeing any concurrent
modifications of the entries while iterating. The duplication of entries
is not guarded, though, as we do not increase the refcount of the
entries that we duplicate right now. This opens us up for a race, as
another thread may concurrently refresh the repository configuration and
thus swap out the current set of entries. As we didn't increase the
refcount, this may lead to the entries being free'd while we iterate
over them in the first thread.

Fix the issue by properly handling the lifecycle of the backend's
entries via `config_file_entries_take` and `git_config_entries_free`,
respectively.
2019-11-05 12:34:19 +01:00
Patrick Steinhardt
0927156a24 config_file: refactor taking entries ref to return an error code
The function to take a reference to the config file's config entries
currently returns the reference via return value. Due to this, it's
harder than necessary to integrate into our typical coding style, as one
needs to make sure that a proper error code is set before erroring out
from the caller. This bites us in `config_file_delete`, where we call
`goto out` directly when `config_file_entries_take` returns `NULL`, but
we actually forget to set up the error code and thus return success.

Fix the issue by refactoring the function to return an error code and
pass the reference via an out-pointer.
2019-11-05 12:34:19 +01:00
Patrick Steinhardt
db301087d6 config_file: remove unused includes 2019-11-05 12:34:19 +01:00
Patrick Steinhardt
c2749849e7 config_file: rename function names
As with the predecessing commit, this commit renames backend functions
of the configuration file backend. This helps to clearly separate
functionality and also to be able to see from backtraces which backend
is currently in use.
2019-11-05 12:34:19 +01:00
Patrick Steinhardt
b30b04a9d0 config_snapshot: rename function names
The configuration snapshot backend has been extracted from the old files
backend back in 2bff84ba4 (config_file: separate out read-only backend,
2019-07-26). To keep code churn manageable, the local functions weren't
renamed yet and thus still have references to the old diskfile backend.
Rename them accordingly to make them easier to understand.
2019-11-05 12:34:14 +01:00
Patrick Steinhardt
82d7a114eb Merge pull request #5293 from csware/config_snapshot-snapshot
Fix crash if snapshotting a config_snapshot
2019-11-05 11:18:14 +01:00
Patrick Steinhardt
45c8d3f410 Merge pull request #5295 from romkatv/fix-diff-res
fix a bug introduced in 8a23597b
2019-11-05 11:13:34 +01:00
romkatv
1886478d57 fix a bug introduced in 8a23597b 2019-11-05 07:48:05 +01:00
Edward Thomson
bf2911d7d0 Merge pull request #5275 from pks-t/pks/reflogs-with-newlines
reflogs: fix behaviour around reflogs with newlines
2019-11-02 07:30:32 -05:00
Sven Strickroth
dadbb33b60 Fix crash if snapshotting a config_snapshot
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2019-11-01 20:04:20 +01:00
Edward Thomson
d5017a1428 Merge pull request #5289 from libgit2/cmn/create-with-signature-verification
commit: verify objects exist in git_commit_with_signature
2019-11-01 07:00:16 -05:00
Carlos Martín Nieto
718f24ad9a commit: verify objects exist in git_commit_with_signature
There can be a significant difference between the system where we created the
buffer (if at all) and when the caller provides us with the contents of a
commit.

Verify that the commit we are being asked to create references objects which do
exist in the target repository.
2019-10-30 20:39:03 +01:00
Carlos Martín Nieto
0974e02f13 commit: add failing tests for object checking for git_commit_with_signature
There can be a significant difference between the system where we created the
buffer (if at all) and when the caller provides us with the contents of a
commit.

Provide some test cases (we have to adapt the existing ones because they refer
to trees and commits which do not exist).
2019-10-30 20:35:48 +01:00
Patrick Steinhardt
2a7d6de335 Merge pull request #5276 from pks-t/pks/patch-fuzzing-fixes
patch_parse: fixes for fuzzing errors
2019-10-29 07:52:31 +01:00
pcpthm
3f998aeee3 Follow 308 redirect in WinHTTP transport 2019-10-26 17:21:29 +09:00
Patrick Steinhardt
a31f4c4b53 Merge pull request #5227 from ddevault/check
apply: add GIT_APPLY_CHECK
2019-10-24 13:16:03 +02:00
Patrick Steinhardt
c405f2312c Merge pull request #5264 from henkesn/refs-unlock-on-commit
refs: unlock unmodified refs on transaction commit
2019-10-24 10:26:43 +02:00
Drew DeVault
02af1fcb69 apply: add GIT_APPLY_CHECK
This adds an option which will check if a diff is applicable without
actually applying it; equivalent to git apply --check.
2019-10-22 10:23:24 -04:00
Patrick Steinhardt
37141ff770 patch_parse: detect overflow when calculating old/new line position
When the patch contains lines close to INT_MAX, then it may happen that
we end up with an integer overflow when calculating the line of the
current diff hunk. Reject such patches as unreasonable to avoid the
integer overflow.

As the calculation is performed on integers, we introduce two new
helpers `git__add_int_overflow` and `git__sub_int_overflow` that perform
the integer overflow check in a generic way.
2019-10-21 20:07:42 +02:00
Patrick Steinhardt
468e3ddc34 patch_parse: fix out-of-bounds read with No-NL lines
We've got two locations where we copy lines into the patch. The first
one is when copying normal " ", "-" or "+" lines, while the second
location gets executed when we copy "\ No newline at end of file" lines.
While the first one correctly uses `git__strndup` to copy only until the
newline, the other one doesn't. Thus, if the line occurs at the end of
the patch and if there is no terminating NUL character, then it may
result in an out-of-bounds read.

Fix the issue by using `git__strndup`, as was already done in the other
location. Furthermore, add allocation checks to both locations to detect
out-of-memory situations.
2019-10-19 17:11:48 +02:00
Patrick Steinhardt
6c6c15e935 patch_parse: reject empty path names
When parsing patch headers, we currently accept empty path names just
fine, e.g. a line "--- \n" would be parsed as the empty filename. This
is not a valid patch format and may cause `NULL` pointer accesses at a
later place as `git_buf_detach` will return `NULL` in that case.

Reject such patches as malformed with a nice error message.
2019-10-19 17:06:11 +02:00
Patrick Steinhardt
223e7e43ef patch_parse: reject patches with multiple old/new paths
It's currently possible to have patches with multiple old path name
headers. As we didn't check for this case, this resulted in a memory
leak when overwriting the old old path with the new old path because we
simply discarded the old pointer.

Instead of fixing this by free'ing the old pointer, we should reject
such patches altogether. It doesn't make any sense for the "---" or
"+++" markers to occur multiple times within a patch n the first place.
This also implicitly fixes the memory leak.
2019-10-19 17:02:53 +02:00
Patrick Steinhardt
b246bed5ab Merge pull request #5269 from durin42/fuzzpatch
fuzzers: add a new fuzzer for patch parsing
2019-10-18 14:59:54 +02:00
Patrick Steinhardt
7968e90f79 refdb_fs: properly parse corrupted reflogs
In previous versions, libgit2 could be coerced into writing reflog
messages with embedded newlines into the reflog by using
`git_stash_save` with a message containing newlines. While the root
cause is fixed now, it was noticed that upstream git is in fact able to
read such corrupted reflog messages just fine.

Make the reflog parser more lenient in order to just skip over
malformatted reflog lines to bring us in line with git. This requires us
to change an existing test that verified that we do indeed _fail_ to
parse such logs.
2019-10-18 13:29:36 +02:00
Patrick Steinhardt
8532ed1184 refdb_fs: convert reflog parsing to use parser
The refdb_fs code to parse the reflog currently uses a hand-rolled
parser. Convert it to use our `git_parse_ctx` structure instead.
2019-10-18 12:26:56 +02:00
Patrick Steinhardt
d8233feb78 reflog: allow adding entries with newlines in their message
Currently, the reflog disallows any entries that have a message with
newlines, as that would effectively break the reflog format, which may
contain a single line per entry, only. Upstream git behaves a bit
differently, though, especially when considering stashes: instead of
rejecting any reflog entry with newlines, git will simply replace
newlines with spaces. E.g. executing 'git stash push -m "foo\nbar"' will
create a reflog entry with "foo bar" as entry message.

This commit adjusts our own logic to stop rejecting commit messages with
newlines. Previously, this logic was part of `git_reflog_append`, only.
There is a second place though where we add reflog entries, which is the
serialization code in the filesystem refdb. As it didn't contain any
sanity checks whatsoever, the refdb would have been perfectly happy to
write malformatted reflog entries to the disk. This is being fixed with
the same logic as for the reflog itself.
2019-10-18 11:30:13 +02:00
Patrick Steinhardt
284816093e stash: refactor code that prepares commit messages 2019-10-18 11:17:08 +02:00
Patrick Steinhardt
ca2d34a844 stash: modernize code style of git_stash_save
The code style of `git_stash_save` doesn't really match our current
coding style. Update it to match our current policies more closely.
2019-10-18 09:16:36 +02:00
Augie Fackler
92e011a715 fuzzers: add a new fuzzer for patch parsing
I was looking at this code anyway because the sr.ht people nerdsniped
me, and it gave me that "I should fuzz this" feeling. So have a fuzzer!
2019-10-17 15:02:36 -04:00
Patrick Steinhardt
c9464bf7ae Merge pull request #5273 from dlax/parse-diff-without-extended-headers
patch_parse: handle patches without extended headers
2019-10-17 18:33:12 +02:00