summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | refdb: check the version of the backend we're about to setEtienne Samson2019-09-051-0/+2
| | | |
| * | | refdb: documentationEtienne Samson2019-09-051-1/+1
| | | |
* | | | Don't use enum for flagsSven Strickroth2019-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Using an `enum` causes trouble when used with C++ as bitwise operations are not possible w/o casting (e.g., `opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY;` is invalid as there is no `&=` operator for `enum`). Signed-off-by: Sven Strickroth <email@cs-ware.de>
* | | | Merge pull request #5232 from pks-t/pks/buffer-ensure-size-oomEdward Thomson2019-09-211-7/+14
|\ \ \ \ | | | | | | | | | | buffer: fix writes into out-of-memory buffers
| * | | | buffer: fix printing into out-of-memory bufferPatrick Steinhardt2019-09-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before printing into a `git_buf` structure, we always call `ENSURE_SIZE` first. This macro will reallocate the buffer as-needed depending on whether the current amount of allocated bytes is sufficient or not. If `asize` is big enough, then it will just do nothing, otherwise it will call out to `git_buf_try_grow`. But in fact, it is insufficient to only check `asize`. When we fail to allocate any more bytes e.g. via `git_buf_try_grow`, then we set the buffer's pointer to `git_buf__oom`. Note that we touch neither `asize` nor `size`. So if we just check `asize > targetsize`, then we will happily let the caller of `ENSURE_SIZE` proceed with an out-of-memory buffer. As a result, we will print all bytes into the out-of-memory buffer instead, resulting in an out-of-bounds write. Fix the issue by having `ENSURE_SIZE` verify that the buffer is not marked as OOM. Add a test to verify that we're not writing into the OOM buffer.
| * | | | buffer: fix infinite loop when growing buffersPatrick Steinhardt2019-09-211-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When growing buffers, we repeatedly multiply the currently allocated number of bytes by 1.5 until it exceeds the requested number of bytes. This has two major problems: 1. If the current number of bytes is tiny and one wishes to resize to a comparatively huge number of bytes, then we may need to loop thousands of times. 2. If resizing to a value close to `SIZE_MAX` (which would fail anyway), then we probably hit an infinite loop as multiplying the current amount of bytes will repeatedly result in integer overflows. When reallocating buffers, one typically chooses values close to 1.5 to enable re-use of resulting memory holes in later reallocations. But because of this, it really only makes sense to use a factor of 1.5 _once_, but not looping until we finally are able to fit it. Thus, we can completely avoid the loop and just opt for the much simpler algorithm of multiplying with 1.5 once and, if the result doesn't fit, just use the target size. This avoids both problems of looping extensively and hitting overflows. This commit also adds a test that would've previously resulted in an infinite loop.
| * | | | buffer: fix memory leak if unable to grow bufferPatrick Steinhardt2019-09-211-1/+4
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | If growing a buffer fails, we set its pointer to the static `git_buf__oom` structure. While we correctly free the old pointer if `git__malloc` returned an error, we do not free it if there was an integer overflow while calculating the new allocation size. Fix this issue by freeing the pointer to plug the memory leak.
* | | | cred: add missing private header in GSSAPI blockEtienne Samson2019-09-211-0/+1
| | | | | | | | | | | | Should have been part of 8bf0f7eb26c65b2b937b1f40a384b9b269b0b76d
* | | | Merge pull request #5206 from tiennou/cmake/pkgconfig-buildingPatrick Steinhardt2019-09-191-22/+11
|\ \ \ \ | |/ / / |/| | | CMake pkg-config modulification
| * | | cmake: add missing requires to the .pc fileEtienne Samson2019-09-141-0/+2
| | | |
| * | | cmake: streamline *.pc file handling via a moduleEtienne Samson2019-09-141-22/+9
| | | |
* | | | cred: separate public interface from low-level detailsEtienne Samson2019-09-137-22/+12
|/ / /
* | | Merge pull request #5195 from tiennou/fix/commitish-smart-pushPatrick Steinhardt2019-09-133-64/+76
|\ \ \ | | | | | | | | smart: use push_glob instead of manual filtering
| * | | smart: implement by-date insertion when revwalkingEtienne Samson2019-08-233-2/+8
| | | |
| * | | revwalk: expose more ways of scheduling commitsEtienne Samson2019-08-232-18/+65
| | | | | | | | | | | | | | | | | | | | | | | | Before we can tweak the revwalk to be more efficent when negotiating, we need to add an "insertion mode" option. Since there's already an implicit set of those, make it visible, at least privately.
| * | | smart: use push_glob instead of manual filteringEtienne Samson2019-08-211-45/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code worked under the assumption that anything under `refs/tags` are tag objects, and all the rest would be peelable to a commit. As it is completely valid to have tags to blobs under a non `refs/tags` ref, this would cause failures when trying to peel a tag to a commit. Fix the broken filtering by switching to `git_revwalk_push_glob`, which already handles this case.
* | | | open:move all cleanup code to cleanup label in git_repository_open_extLaurence McGlashan2019-09-101-9/+7
| | | |
* | | | open:fix memory leak when passing NULL to git_repository_open_extLaurence McGlashan2019-09-101-1/+6
| | | |
* | | | Merge pull request #5209 from mkostyuk/apply-wrong-patchEdward Thomson2019-09-091-1/+1
|\ \ \ \ | | | | | | | | | | apply: Fix a patch corruption related to EOFNL handling
| * | | | apply: Fix a patch corruption related to EOFNL handlingMax Kostyukevich2019-08-201-1/+1
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use of apply's API can lead to an improper patch application and a corruption of the modified file. The issue is caused by mishandling of the end of file changes if there are several hunks to apply. The new line character is added to a line from a wrong hunk. The solution is to modify apply_hunk() to add the newline character at the end of a line from a right hunk.
* | | | Merge pull request #5210 from buddyspike/masterEdward Thomson2019-09-091-3/+6
|\ \ \ \ | | | | | | | | | | ignore: correct handling of nested rules overriding wild card unignore
| * | | | ignore: correct handling of nested rules overriding wild card unignorebuddyspike2019-08-281-3/+6
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | problem: filesystem_iterator loads .gitignore files in top-down order. subsequently, ignore module evaluates them in the order they are loaded. this creates a problem if we have unignored a rule (using a wild card) in a sub dir and ignored it again in a level further below (see the test included in this patch). solution: process ignores in reverse order. closes #4963
* | | | Merge pull request #5214 from pks-t/pks/diff-iterator-allocation-fixesEdward Thomson2019-09-092-79/+130
|\ \ \ \ | | | | | | | | | | Memory allocation fixes for diff generator
| * | | | iterator: remove duplicate memsetPatrick Steinhardt2019-08-271-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | When allocating new tree iterator frames, we zero out the allocated memory twice. Remove one of the `memset` calls.
| * | | | iterator: avoid leaving partially initialized frame on stackPatrick Steinhardt2019-08-271-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When allocating tree iterator entries, we use GIT_ERROR_ALLOC_CHECK` to check whether the allocation has failed. The macro will cause the function to immediately return, though, leaving behind a partially initialized iterator frame. Fix the issue by manually checking for memory allocation errors and using `goto done` in case of an error, popping the iterator frame.
| * | | | diff_generate: detect memory allocation errors when preparing optsPatrick Steinhardt2019-08-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When preparing options for the two iterators that are about to be diffed, we allocate a common prefix for both iterators depending on the options passed by the user. We do not check whether the allocation was successful, though. In fact, this isn't much of a problem, as using a `NULL` prefix is perfectly fine. But in the end, we probably want to detect that the system doesn't have any memory left, as we're unlikely to be able to continue afterwards anyway. While the issue is being fixed in the newly created function `diff_prepare_iterator_opts`, it has been previously existing in the previous macro `DIFF_FROM_ITERATORS` already.
| * | | | diff_generate: refactor `DIFF_FROM_ITERATORS` macro of doomPatrick Steinhardt2019-08-271-72/+121
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the `DIFF_FROM_ITERATORS` does make it shorter to implement the various `git_diff_foo_to_bar` functions, it is a complex and unreadable beast that implicitly assumes certain local variable names. This is not something desirable to have at all and obstructs understanding and more importantly debugging the code by quite a bit. The `DIFF_FROM_ITERATORS` macro basically removed the burden of having to derive the options for both iterators from a pair of iterator flags and the diff options. This patch introduces a new function that does the that exact and refactors all callers to manage the iterators by themselves. As we potentially need to allocate a shared prefix for the iterator, we need to tell the caller to allocate that prefix as soon as the options aren't required anymore. Thus, the function has a `char **prefix` out pointer that will get set to the allocated string and subsequently be free'd by the caller. While this patch increases the line count, I personally deem this to an acceptable tradeoff for increased readbiblity.
* | | | Merge pull request #5212 from libgit2/ethomson/creds_for_schemeEdward Thomson2019-09-092-9/+17
|\ \ \ \ | |_|/ / |/| | | Use an HTTP scheme that supports the given credentials
| * | | http: ensure the scheme supports the credentialsethomson/creds_for_schemeIan Hattendorf2019-08-231-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | When a server responds with multiple scheme support - for example, Negotiate and NTLM are commonly used together - we need to ensure that we choose a scheme that supports the credentials.
| * | | http: allow dummy negotiation scheme to fail to actEdward Thomson2019-08-212-5/+8
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The dummy negotiation scheme is used for known authentication strategies that do not wish to act. For example, when a server requests the "Negotiate" scheme but libgit2 is not built with Negotiate support, and will use the "dummy" strategy which will simply not act. Instead of setting `out` to NULL and returning a successful code, return `GIT_PASSTHROUGH` to indicate that it did not act and catch that error code.
* | | Merge pull request #5208 from mkostyuk/apply-removed-new-fileEdward Thomson2019-08-271-3/+6
|\ \ \ | | | | | | | | apply: git_apply_to_tree fails to apply patches that add new files
| * | | apply: git_apply_to_tree fails to apply patches that add new filesMax Kostyukevich2019-08-201-3/+6
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | Merge pull request #5189 from libgit2/ethomson/attrs_from_headEdward Thomson2019-08-275-14/+102
|\ \ \ | | | | | | | | Optionally read `.gitattributes` from HEAD
| * | | blob: optionally read attributes from repositoryEdward Thomson2019-08-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | | filter: optionally read attributes from repositoryEdward Thomson2019-08-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | | attr: optionally read attributes from repositoryEdward Thomson2019-08-113-7/+56
| | | | | | | | | | | | | | | | | | | | When `GIT_ATTR_CHECK_INCLUDE_HEAD` is specified, read `gitattribute` files that are checked into the repository at the HEAD revision.
| * | | blob: allow blob filtering to ignore system gitattributesEdward Thomson2019-08-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | | filter: add GIT_FILTER_NO_SYSTEM_ATTRIBUTES optionEdward Thomson2019-08-111-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | Allow system-wide attributes (the ones specified in `/etc/gitattributes`) to be ignored if the flag `GIT_FILTER_NO_SYSTEM_ATTRIBUTES` is specified.
| * | | blob: deprecate `git_blob_filtered_content`Edward Thomson2019-08-111-16/+16
| | | | | | | | | | | | | | | | Users should now use `git_blob_filter`.
| * | | blob: introduce git_blob_filterEdward Thomson2019-08-111-4/+29
| | | | | | | | | | | | | | | | | | | | Provide a function to filter blobs that allows for more functionality than the existing `git_blob_filtered_content` function.
* | | | Merge pull request #5196 from pks-t/pks/config-include-onbranchEdward Thomson2019-08-271-1/+53
|\ \ \ \ | | | | | | | | | | config: implement "onbranch" conditional
| * | | | config: implement "onbranch" conditionalPatrick Steinhardt2019-08-011-1/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With Git v2.23.0, the conditional include mechanism gained another new conditional "onbranch". As the name says, it will cause a file to be included if the "onbranch" pattern matches the currently checked out branch. Implement this new condition and add a bunch of tests.
* | | | | Merge pull request #5213 from boardwalk/dskorupski/fix_include_caseEdward Thomson2019-08-251-1/+1
|\ \ \ \ \ | | | | | | | | | | | | Fix include casing for case-sensitive filesystems.
| * | | | | Fix include casing for case-sensitive filesystems.Dan Skorupski2019-08-241-1/+1
| | | | | |
* | | | | | Merge pull request #5054 from tniessen/util-use-64-bit-timerEdward Thomson2019-08-232-17/+2
|\ \ \ \ \ \ | | | | | | | | | | | | | | util: use 64 bit timer on Windows
| * | | | | | cmake: move _WIN32_WINNT definitions to rootTobias Nießen2019-08-171-2/+0
| | | | | | |
| * | | | | | util: use 64 bit timer on WindowsTobias Nießen2019-07-291-15/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git__timer was originally implemented using a 32 bit timer since Windows XP did not support GetTickCount64. Windows XP was discontinued five years ago, so it should be safe to use the new API. As a benefit, we do not need to care about overflows for the next 585 million years.
* | | | | | | util: do not perform allocations in insertsortPatrick Steinhardt2019-08-232-28/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | | xdiff: catch memory allocation errorsPatrick Steinhardt2019-08-232-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | | transports: http: check for memory allocation failuresPatrick Steinhardt2019-08-232-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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`.