Commit Graph

12616 Commits

Author SHA1 Message Date
Carlos Martín Nieto
5eafc37e95 regex: make sure to link against PCRE2's regex functions
PCRE2's header defines just the basic names but that means that we'll link
against libc's version while using PCRE2's struct definitions, leading to
crashes. To work around this, package maintainers have added prefixes to the
exported functions so we can link against them.

But the definitions in the header are still of the basic names so we need to
tell the compiler/linker to replace these names when linking.
2019-09-01 14:59:59 +02:00
Edward Thomson
5fc27aac6f Merge pull request #5208 from mkostyuk/apply-removed-new-file
apply: git_apply_to_tree fails to apply patches that add new files
2019-08-27 13:38:08 -04:00
Edward Thomson
5498c318a2 apply: free test data 2019-08-27 13:10:53 -04:00
Edward Thomson
6de48085b6 Merge pull request #5189 from libgit2/ethomson/attrs_from_head
Optionally read `.gitattributes` from HEAD
2019-08-27 11:29:24 -04:00
Edward Thomson
aaa48d06d9 Merge pull request #5196 from pks-t/pks/config-include-onbranch
config: implement "onbranch" conditional
2019-08-27 11:26:50 -04:00
Edward Thomson
4e20c7b137 Merge pull request #5213 from boardwalk/dskorupski/fix_include_case
Fix include casing for case-sensitive filesystems.
2019-08-25 22:11:39 -04:00
Dan Skorupski
44d5e47d8c Fix include casing for case-sensitive filesystems. 2019-08-24 10:39:56 -05:00
Edward Thomson
6031978892 Merge pull request #5054 from tniessen/util-use-64-bit-timer
util: use 64 bit timer on Windows
2019-08-23 09:58:15 -04:00
Edward Thomson
feac594588 Merge pull request #5200 from pks-t/pks/memory-allocation-audit
Memory allocation audit
2019-08-23 09:42:35 -04:00
Patrick Steinhardt
8cbef12d45 util: do not perform allocations in insertsort
Our hand-rolled fallback sorting function `git__insertsort_r` does an
in-place sort of the given array. As elements may not necessarily be
pointers, it needs a way of swapping two values of arbitrary size, which
is currently implemented by allocating a temporary buffer of the
element's size. This is problematic, though, as the emulated `qsort`
interface doesn't provide any return values and thus cannot signal an
error if allocation of that temporary buffer has failed.

Convert the function to swap via a temporary buffer allocated on the
stack. Like this, it can `memcpy` contents of both elements in small
batches without requiring a heap allocation. The buffer size has been
chosen such that in most cases, a single iteration of copying will
suffice. Most importantly, it can fully contain `git_oid` structures and
pointers.

Add a bunch of tests for the `git__qsort_r` interface to verify nothing
breaks. Furthermore, this removes the declaration of `git__insertsort_r`
and makes it static as it is not used anywhere else.
2019-08-23 12:54:02 +02:00
Patrick Steinhardt
f3b3e543bc xdiff: catch memory allocation errors
The xdiff code contains multiple call sites where the results of
`xdl_malloc` are not being checked for memory allocation errors.

Add checks to fix possible segfaults due to `NULL` pointer accesses.
2019-08-23 12:54:01 +02:00
Patrick Steinhardt
c2dd895a8d transports: http: check for memory allocation failures
When allocating a chunk that is used to write to HTTP streams, we do not
check for memory allocation errors. This may lead us to write to a
`NULL` pointer and thus cause a segfault.

Fix this by adding a call to `GIT_ERROR_CHECK_ALLOC`.
2019-08-23 12:54:01 +02:00
Patrick Steinhardt
08699541ea trailer: check for memory allocation errors
The "trailer.c" code has been copied mostly verbatim from git.git with
minor adjustments, only. As git.git's `xmalloc` function, which aborts
on memory allocation errors, has been swapped out for `git_malloc`,
which doesn't abort, we may inadvertently access `NULL` pointers.

Add checks to fix this.
2019-08-23 12:54:01 +02:00
Patrick Steinhardt
8c7d976136 posix: fix direct use of malloc
In "posix.c" there are multiple callsites which execute `malloc` instead
of `git__malloc`. Thus, users of library are not able to track these
allocations with a custom allocator.

Convert these call sites to use `git__malloc` instead.
2019-08-23 12:54:01 +02:00
Patrick Steinhardt
a477bff110 indexer: catch OOM when adding expected OIDs
When adding OIDs to the indexer's map of yet-to-be-seen OIDs to verify
that packfiles are complete, we do so by first allocating a new OID and
then calling `git_oidmap_set` on it. There was no check for memory
allocation errors in place, though, leading to possible segfaults due to
trying to copy data to a `NULL` pointer.

Verify the result of `git__malloc` with `GIT_ERROR_CHECK_ALLOC` to fix
the issue.
2019-08-23 12:54:01 +02:00
Patrick Steinhardt
d4fe402b05 merge: check return value of git_commit_list_insert
The function `git_commit_list_insert` dynamically allocates memory and
may thus fail to insert a given commit, but we didn't check for that in
several places in "merge.c".

Convert surrounding functions to return error codes and check whether
`git_commit_list_insert` was successful, returning an error if not.
2019-08-23 12:54:01 +02:00
Patrick Steinhardt
c04861885c blame_git: detect memory allocation errors
The code in "blame_git.c" was mostly imported from git.git with only
minor changes. One of these changes was to use our own allocators
instead of git's `xmalloc`, but there's a subtle difference: `xmalloc`
would abort the program if unable to allocate any memory, bit
`git__malloc` doesn't. As we didn't check for memory allocation errors
in some places, we might inadvertently dereference a `NULL` pointer in
out-of-memory situations.

Convert multiple functions to return proper error codes and add calls to
`GIT_ERROR_CHECK_ALLOC` to fix this.
2019-08-23 12:54:01 +02:00
Max Kostyukevich
dceedbb809 apply: Test for git_apply_to_tree failures when new files are added
Introduce an unit test to validate if git_apply_to_tree() fails when an
applied patch adds new files.
2019-08-21 15:03:50 +03:00
Max Kostyukevich
de4bc2bd6d apply: git_apply_to_tree fails to apply patches that add new files
git_apply_to_tree() cannot be used apply patches with new files. An attempt
to apply such a patch fails because git_apply_to_tree() tries to remove a
non-existing file from an old index.

The solution is to modify git_apply_to_tree() to git_index_remove() when the
patch states that the modified files is removed.
2019-08-20 03:29:45 +03:00
Tobias Nießen
071750a386 cmake: move _WIN32_WINNT definitions to root 2019-08-17 17:53:00 +02:00
Edward Thomson
0f40e68e2f Merge pull request #5187 from ianhattendorf/fix/clone-whitespace
clone: don't decode URL percent encodings
2019-08-14 09:05:07 +01:00
Edward Thomson
08cfa43d0e Merge pull request #5202 from libgit2/users/ethomson/security_updates
Security updates from 0.28.3
2019-08-13 18:17:11 +01:00
Edward Thomson
df3f18acf0 changelog: include security updates 2019-08-13 17:56:06 +01:00
Patrick Steinhardt
57a9ccd5e2 commit_list: fix possible buffer overflow in commit_quick_parse
The function `commit_quick_parse` provides a way to quickly parse
parts of a commit without storing or verifying most of its
metadata. The first thing it does is calculating the number of
parents by skipping "parent " lines until it finds the first
non-parent line. Afterwards, this parent count is passed to
`alloc_parents`, which will allocate an array to store all the
parent.

To calculate the amount of storage required for the parents
array, `alloc_parents` simply multiplicates the number of parents
with the respective elements's size. This already screams "buffer
overflow", and in fact this problem is getting worse by the
result being cast to an `uint32_t`.

In fact, triggering this is possible: git-hash-object(1) will
happily write a commit with multiple millions of parents for you.
I've stopped at 67,108,864 parents as git-hash-object(1)
unfortunately soaks up the complete object without streaming
anything to disk and thus will cause an OOM situation at a later
point. The point here is: this commit was about 4.1GB of size but
compressed down to 24MB and thus easy to distribute.

The above doesn't yet trigger the buffer overflow, thus. As the
array's elements are all pointers which are 8 bytes on 64 bit, we
need a total of 536,870,912 parents to trigger the overflow to
`0`. The effect is that we're now underallocating the array
and do an out-of-bound writes. As the buffer is kindly provided
by the adversary, this may easily result in code execution.

Extrapolating from the test file with 67m commits to the one with
536m commits results in a factor of 8. Thus the uncompressed
contents would be about 32GB in size and the compressed ones
192MB. While still easily distributable via the network, only
servers will have that amount of RAM and not cause an
out-of-memory condition previous to triggering the overflow. This
at least makes this attack not an easy vector for client-side use
of libgit2.
2019-08-13 17:56:06 +01:00
Johannes Schindelin
cb1439c9d3 config: validate ownership of C:\ProgramData\Git\config before using it
When the VirtualStore feature is in effect, it is safe to let random
users write into C:\ProgramData because other users won't see those
files. This seemed to be the case when we introduced support for
C:\ProgramData\Git\config.

However, when that feature is not in effect (which seems to be the case
in newer Windows 10 versions), we'd rather not use those files unless
they come from a trusted source, such as an administrator.

This change imitates the strategy chosen by PowerShell's native OpenSSH
port to Windows regarding host key files: if a system file is owned
neither by an administrator, a system account, or the current user, it
is ignored.
2019-08-13 17:56:06 +01:00
Ian Hattendorf
62b8013880 clone: Remove whitespace ssh test
Will add later when infrastructure is configured
2019-08-13 09:10:10 -07:00
Ian Hattendorf
b15e7f2d50 clone: Update whitespace test url 2019-08-12 09:56:51 -07:00
Edward Thomson
5774b2b134 Merge pull request #5113 from pks-t/pks/stash-perf
stash: avoid recomputing tree when committing worktree
2019-08-11 23:42:45 +01:00
Edward Thomson
cdbbb36482 filter: test second-level in-repo .gitattributes
Ensure that a `.gitattributes` file that is deeper in the tree is
honored, not just an attributes file at the root.
2019-08-11 21:32:03 +01:00
Edward Thomson
ff25ec8356 tests: add a subdirectory to crlf tests
Add a subdirectory in the crlf.git bare repository that has a
second-level .gitattribute file.
2019-08-11 21:32:03 +01:00
Edward Thomson
3661e35e4e filter: test we can filter a blob in a bare repo 2019-08-11 21:32:02 +01:00
Edward Thomson
42bacbc603 Merge pull request #5121 from pks-t/pks/variadic-errors
Variadic macros
2019-08-11 21:06:19 +01:00
Edward Thomson
fba3bf7978 blob: optionally read attributes from repository
When `GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD` is passed to
`git_blob_filter`, read attributes from `gitattributes` files that
are checked in to the repository at the HEAD revision.  This passes
the flag `GIT_FILTER_ATTRIBUTES_FROM_HEAD` to the filter functions.
2019-08-11 20:47:59 +01:00
Edward Thomson
f0f27c1c2b filter: optionally read attributes from repository
When `GIT_FILTER_ATTRIBUTES_FROM_HEAD` is specified, configure the
filter to read filter attributes from `gitattributes` files that are
checked in to the repository at the HEAD revision.  This passes the flag
`GIT_ATTR_CHECK_INCLUDE_HEAD` to the attribute reading functions.
2019-08-11 20:47:59 +01:00
Edward Thomson
4fd5748c4b attr: optionally read attributes from repository
When `GIT_ATTR_CHECK_INCLUDE_HEAD` is specified, read `gitattribute`
files that are checked into the repository at the HEAD revision.
2019-08-11 20:47:59 +01:00
Edward Thomson
a5392eae3d blob: allow blob filtering to ignore system gitattributes
Introduce `GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES`, which tells
`git_blob_filter` to ignore the system-wide attributes file, usually
`/etc/gitattributes`.

This simply passes the appropriate flag to the attribute loading code.
2019-08-11 20:47:59 +01:00
Edward Thomson
22eb12afef filter: add GIT_FILTER_NO_SYSTEM_ATTRIBUTES option
Allow system-wide attributes (the ones specified in
`/etc/gitattributes`) to be ignored if the flag
`GIT_FILTER_NO_SYSTEM_ATTRIBUTES` is specified.
2019-08-11 20:47:59 +01:00
Edward Thomson
e7fc8601ff filter: test that system attributes can be ignored
Test that we can optionally ignore system attributes when filtering a
blob.
2019-08-11 20:47:59 +01:00
Edward Thomson
45ddb58634 filter: document GIT_FILTER_ALLOW_UNSAFE 2019-08-11 20:47:59 +01:00
Edward Thomson
c66f7605e5 filter: ensure system attributes are read
By default, `/etc/gitattributes` (or the system equivalent) is read to
provide attributes.  Ensure that, by default, this is read when
filtering blobs.
2019-08-11 20:47:59 +01:00
Edward Thomson
fa1a4c77f5 blob: deprecate git_blob_filtered_content
Users should now use `git_blob_filter`.
2019-08-11 20:47:59 +01:00
Edward Thomson
a008ceeaf7 blob: convert users of git_blob_filtered_content
Move users of `git_blob_filtered_content` to `git_blob_filter`.
2019-08-11 20:47:59 +01:00
Edward Thomson
a32ab076bd blob: introduce git_blob_filter
Provide a function to filter blobs that allows for more functionality
than the existing `git_blob_filtered_content` function.
2019-08-11 20:47:59 +01:00
Patrick Steinhardt
b0692d6b3e Merge pull request #4913 from implausible/feature/signing-rebase-commits
Add sign capability to git_rebase_commit
2019-08-09 09:01:56 +02:00
Tyler Ang-Wanek
998f9c15fd fixup: strange indentation 2019-08-07 07:21:27 -07:00
Edward Thomson
f627ba6c7f Merge pull request #5197 from pks-t/pks/remote-ifdeffed-block
remote: remove unused block of code
2019-08-02 13:18:07 +01:00
Patrick Steinhardt
24c491ed00 Merge pull request #5146 from scottfurry/StaticFixesExamples
Adjust printf specifiers in examples code
2019-08-02 07:58:11 +02:00
Patrick Steinhardt
e23c0b18e6 remote: remove unused block of code
In "remote.c", we have a chunk of code that is #ifdef'fed out via
`#if 0` with a comment that we could export it as a helper function.
The code was implemented in 2013 and ifdef'fed in 2014, which shows that
there's clearly no interest in having such a helper at all.

As this block has recently created some confusion about `p_getenv` due
to it containing the only reference to that function in our codebase,
let's remove this block altogether.
2019-08-02 07:52:58 +02:00
Patrick Steinhardt
d588de7cd6 Merge pull request #5191 from eaigner/master
config: check if we are running in a sandboxed environment
2019-08-02 07:51:02 +02:00
Scott Furry
73a186f28a Adjust printf specifiers in examples code
Static analysis of example code found multiple findings of `printf` usage
where filling value is members of git_indexer_progress object. Specifier
used was for signed int but git_indexer_progress members are typed as
unsigned ints. `printf` specifiers were altered to match type.
2019-08-01 12:52:12 -06:00