summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* ci: only push docs from the libgit2/libgit2 repoethomson/publish_docs_on_masterEdward Thomson2019-12-031-1/+1
| | | | | | | | | | Users may fork libgit2 and run libgit2's CI on that, which is delightful! However, if they do, we'll fail the documentation publish phase, which is correct (because we don't allow them to publish _their_ version of the docs) but regrettable (since it should not fail). Only run the documentation publish phase when we merge branches into the libgit2/libgit2 repo.
* Merge pull request #5314 from pks-t/pks/dll-main-removalEdward Thomson2019-12-013-47/+12
|\ | | | | global: convert to fiber-local storage to fix exit races
| * global: convert to fiber-local storage to fix exit racesPatrick Steinhardt2019-11-293-47/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Windows platforms, we automatically clean up the thread-local storage upon detaching a thread via `DllMain()`. The thing is that this happens for every thread of applications that link against the libgit2 DLL, even those that don't have anything to do with libgit2 itself. As a result, we cannot assume that these unsuspecting threads make use of our `git_libgit2_init()` and `git_libgit2_shutdow()` reference counting, which may lead to racy situations: Thread 1 Thread 2 git_libgit2_shutdown() DllMain(DETACH_THREAD) git__free_tls_data() git_atomic_dec() == 0 git__free_tls_data() TlsFree(_tls_index) TlsGetValue(_tls_index) Due to the second thread never having executed `git_libgit2_init()`, the first thread will clean up TLS data and as a result also free the `_tls_index` variable. When detaching the second thread, we unconditionally access the now-free'd `_tls_index` variable, which is obviously not going to work out well. Fix the issue by converting the code to use fiber-local storage instead of thread-local storage. While FLS will behave the exact same as TLS if no fibers are in use, it does allow us to specify a destructor similar to the one that is accepted by pthread_key_create(3P). Like this, we do not have to manually free indices anymore, but will let the FLS handle calling the destructor. This allows us to get rid of `DllMain()` completely, as we only used it to keep track of when threads were exiting and results in an overall simplification of TLS cleanup.
* | Merge pull request #5315 from ↵Edward Thomson2019-12-011-2/+2
|\ \ | | | | | | | | | | | | kastiglione/dl/fix-copypaste-in-git_cherrypick_commit-docstring Fix copy&paste in git_cherrypick_commit docstring
| * | Fix copy&paste in git_cherrypick_commit docstringDave Lee2019-11-291-2/+2
| | |
* | | Merge pull request #5312 from pks-t/pks/patch-base85-overflowEdward Thomson2019-12-013-1/+16
|\ \ \ | |_|/ |/| | patch_parse: fix out-of-bounds reads caused by integer underflow
| * | patch_parse: fix out-of-bounds reads caused by integer underflowPatrick Steinhardt2019-11-283-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch format for binary files is a simple Base85 encoding with a length byte as prefix that encodes the current line's length. For each line, we thus check whether the line's actual length matches its expected length in order to not faultily apply a truncated patch. This also acts as a check to verify that we're not reading outside of the line's string: if (encoded_len > ctx->parse_ctx.line_len - 1) { error = git_parse_err(...); goto done; } There is the possibility for an integer underflow, though. Given a line with a single prefix byte, only, `line_len` will be zero when reaching this check. As a result, subtracting one from that will result in an integer underflow, causing us to assume that there's a wealth of bytes available later on. Naturally, this may result in an out-of-bounds read. Fix the issue by checking both `encoded_len` and `line_len` for a non-zero value. The binary format doesn't make use of zero-length lines anyway, so we need to know that there are both encoded bytes and remaining characters available at all. This patch also adds a test that works based on the last error message. Checking error messages is usually too tightly coupled, but in fact parsing the patch failed even before the change. Thus the only possibility is to use e.g. Valgrind, but that'd result in us not catching issues when run without Valgrind. As a result, using the error message is considered a viable tradeoff as we know that we didn't start decoding Base85 in the first place.
* | | Merge pull request #5311 from pks-t/pks/clar-trace-warningEdward Thomson2019-11-291-10/+16
|\ \ \ | | | | | | | | tests: fix compiler warning if tracing is disabled
| * | | tests: fix compiler warning if tracing is disabledPatrick Steinhardt2019-11-281-10/+16
| |/ / | | | | | | | | | | | | | | | | | | | | | If building libgit2's test suite with tracing disabled, then the compiler will emit a warning due to the unused `message_prefix` function. Fix the issue by wrapping the whole file into ifdef's for `GIT_TRACE` and providing separate empty function implementations for both `cl_global_trace_register` and `cl_global_trace_disable`.
* | | Merge pull request #5313 from pks-t/pks/config-invasiveEdward Thomson2019-11-291-0/+3
|\ \ \ | |/ / |/| | tests: config: only test parsing huge file with GITTEST_INVASIVE_SPEED
| * | tests: config: only test parsing huge file with GITTEST_INVASIVE_SPEEDPatrick Steinhardt2019-11-281-0/+3
|/ / | | | | | | | | | | | | | | The test in config::stress::huge_section_with_many_values takes quite a long time to execute. Hide it behind the GITTEST_INVASIVE_SPEED environment varibale to not needlessly blow up execution time of tests. As this environment variable is being set by the continuous integration, we will execute it regularly anyway.
* | Merge pull request #5306 from herrerog/patchidPatrick Steinhardt2019-11-289-74/+130
|\ \ | | | | | | diff: complete support for git patchid
| * | diff: make patchid computation work with all types of commits.Gregory Herrero2019-11-283-61/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current implementation of patchid is not computing a correct patchid when given a patch where, for example, a new file is added or removed. Some more corner cases need to be handled to have same behavior as git patch-id command. Add some more tests to cover those corner cases. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
| * | patch_parse: correct parsing of patch containing not shown binary data.Gregory Herrero2019-11-193-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | When not shown binary data is added or removed in a patch, patch parser is currently returning 'error -1 - corrupt git binary header at line 4'. Fix it by correctly handling case where binary data is added/removed. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
| * | diff_print: add support for GIT_DIFF_FORMAT_PATCH_ID.Gregory Herrero2019-11-192-1/+7
| | | | | | | | | | | | | | | | | | | | | Git is generating patch-id using a stripped down version of a patch where hunk header and index information are not present. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
| * | diff_print: add a new 'print_index' flag when printing diff.Gregory Herrero2019-11-193-9/+17
| |/ | | | | | | | | | | | | | | | | Add a new 'print_index' flag to let the caller decide whether or not 'index <oid>..<oid>' should be printed. Since patch id needs not to have index when hashing a patch, it will be useful soon. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
* | Merge pull request #5243 from pks-t/pks/config-optimize-memPatrick Steinhardt2019-11-283-74/+40056
|\ \ | | | | | | Memory optimizations for config entries
| * | config_entries: micro-optimize storage of multivarsPatrick Steinhardt2019-11-053-3/+40036
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Multivars are configuration entries that have many values for the same name; we can thus micro-optimize this case by just retaining the name of the first configuration entry and freeing all the others, letting them point to the string of the first entry. The attached test case is an extreme example that demonstrates this. It contains a section name that is approximately 500kB in size with 20.000 entries "a=b". Without the optimization, this would require at least 20000*500kB bytes, which is around 10GB. With this patch, it only requires 500kB+20000*1B=20500kB. The obvious culprit here is the section header, which we repeatedly include in each of the configuration entry's names. This makes it very easier for an adversary to provide a small configuration file that disproportionally blows up in memory during processing and is thus a feasible way for a denial-of-service attack. Unfortunately, we cannot fix the root cause by e.g. having a separate "section" field that may easily be deduplicated due to the `git_config_entry` structure being part of our public API. So this micro-optimization is the best we can do for now.
| * | config_entries: only keep track of a single entry listPatrick Steinhardt2019-11-051-73/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Whenever adding a configuration entry to the config entries structure, we allocate two list heads: - The first list head is added to the global list of config entries in order to be able to iterate over configuration entries in the order they were originally added. - The second list head is added to the map of entries in order to efficiently look up an entry by its name. If no entry with the same name exists in the map, then we add the new entry to the map directly. Otherwise, we append the new entry's list head to the pre-existing entry's list in order to keep track of multivars. While the former usecase is perfectly sound, the second usecase can be optimized. The only reason why we keep track of multivar entries in another separate list is to be able to determine whether an entry is unique or not by seeing whether its `next` pointer is set. So we keep track of a complete list of multivar entries just to have a single bit of information of whether it has other multivar entries with the same entry name. We can completely get rid of this secondary list by just adding a `first` field to the list structure itself. When executing `git_config_entries_append`, we will then simply check whether the configuration map already has an entry with the same name -- if so, we will set the `first` to zero to indicate that it is not the initial entry anymore. Instead of a second list head in the map, we can thus now directly store the list head of the first global list inside of the map and just refer to that bit. Note that the more obvious solution would be to store a `unique` field instead of a `first` field. But as we will only ever inspect the `first` field of the _last_ entry that has been moved into the map, these are semantically equivalent in that case. Having a `first` field also allows for a minor optimization: for multivar values, we can free the `name` field of all entries that are _not_ first and have them point to the name of the first entry instead.
| * | config_entries: mark local functions as staticPatrick Steinhardt2019-11-051-3/+3
| | | | | | | | | | | | | | | Some functions which are only used in "config_entries.c" are not marked as static, which is being fixed by this very commit.
* | | Merge pull request #5307 from palmin/hash_sha256Patrick Steinhardt2019-11-282-0/+16
|\ \ \ | | | | | | | | ssh: include sha256 host key hash when supported
| * | | ssh: include sha256 host key hash when supportedAnders Borum2019-11-202-0/+16
| | |/ | |/|
* | | Merge pull request #5272 from tiennou/examples/cli-ificationPatrick Steinhardt2019-11-2826-452/+521
|\ \ \ | | | | | | | | Various examples shape-ups
| * | | examples: buff up rev-list by adding OID supportEtienne Samson2019-11-061-22/+58
| | | | | | | | | | | | | | | | This allows the example to be used as a quick revwalk test harness.
| * | | examples: normalize decls and usage of options structsEtienne Samson2019-11-0612-89/+86
| | | |
| * | | examples: add comments to add.cEtienne Samson2019-11-061-0/+2
| | | |
| * | | examples: modernize add codeEtienne Samson2019-11-061-45/+49
| | | |
| * | | examples: extract argument conversion helperEtienne Samson2019-11-062-0/+19
| | | |
| * | | examples: fixup for-each-ref styleEtienne Samson2019-11-061-33/+33
| | | |
| * | | examples: keep track of whether we processed a "--" argEtienne Samson2019-11-065-10/+23
| | | |
| * | | examples: move "args" to its own headerEtienne Samson2019-11-064-239/+251
| | | |
| * | | examples: remove duplicate includes from common.cEtienne Samson2019-11-061-9/+1
| | | |
| * | | global: DRY includes of assert.hEtienne Samson2019-11-0610-14/+4
| | | |
| * | | examples: add missing include barriersEtienne Samson2019-11-061-0/+4
| | | |
| * | | examples: add *.h files to IDEsEtienne Samson2019-11-061-1/+1
| | | |
* | | | Merge pull request #5309 from libgit2/ethomson/tracePatrick Steinhardt2019-11-282-10/+34
|\ \ \ \ | | | | | | | | | | Improve trace support in tests
| * | | | tests: optionally show test execution tracingethomson/traceEdward Thomson2019-11-271-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | Only show test trace execution when the CLAR_TRACE_TESTS environment variable is set. This reduces the noise during tracing.
| * | | | tests: display trace level with prefix in testsEdward Thomson2019-11-271-8/+24
| | | | |
| * | | | trace: enable tracing by defaultEdward Thomson2019-11-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Tracing is meant to be extremely low-impact when not enabled. We currently ship no tracing calls in libgit2, but if / when we do, the tracing infrastructure is created to skip tracing as quickly as possible. It should compile to a simple test when tracing is off. Thus, there's on reason to not enable it by default.
* | | | | Merge pull request #5123 from libgit2/ethomson/off_tPatrick Steinhardt2019-11-2852-178/+211
|\ \ \ \ \ | | | | | | | | | | | | Move `git_off_t` to `git_object_size_t`
| * | | | | internal: use off64_t instead of git_off_tethomson/off_tEdward Thomson2019-11-2513-78/+78
| | | | | | | | | | | | | | | | | | | | | | | | Prefer `off64_t` internally.
| * | | | | integer: use int64_t's for checksEdward Thomson2019-11-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | Use int64_t internally for type visibility.
| * | | | | offmap: store off64_t's instead of git_off_t'sEdward Thomson2019-11-252-14/+14
| | | | | | | | | | | | | | | | | | | | | | | | Prefer `off64_t` to `git_off_t` internally for visibility.
| * | | | | mmap: use a 64-bit signed type `off64_t` for mmapEdward Thomson2019-11-256-7/+19
| | | | | | | | | | | | | | | | | | | | | | | | Prefer `off64_t` to `git_off_t` for internal visibility.
| * | | | | mmap: remove unnecessary assertionEdward Thomson2019-11-251-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | 64 bit types are always 64 bit.
| * | | | | example: use `git_object_size_t` for object sizeEdward Thomson2019-11-221-1/+1
| | | | | |
| * | | | | blame: use a size_t for the bufferEdward Thomson2019-11-222-3/+10
| | | | | |
| * | | | | filestamp: use `uint64_t` for object sizeEdward Thomson2019-11-222-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of using a signed type (`off_t`) use an unsigned `uint64_t` for the size of the files.
| * | | | | odb: use `git_object_size_t` for object sizeEdward Thomson2019-11-223-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of using a signed type (`off_t`) use a new `git_object_size_t` for the sizes of objects.
| * | | | | futils_filesize: use `uint64_t` for object sizeEdward Thomson2019-11-225-22/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of using a signed type (`off_t`) use `uint64_t` for the maximum size of files.