summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | | | | patch_parse: treat complete line after "---"/"+++" as pathPatrick Steinhardt2017-11-111-8/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When parsing the "---" and "+++" line, we stop after the first whitespace inside of the filename. But as files containing whitespaces do not need to be quoted, we should instead use the complete line here. This fixes parsing patches with unquoted paths with whitespaces.
* | | | | | | Fix unpack double freelhchavez2017-12-232-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If an element has been cached, but then the call to packfile_unpack_compressed() fails, the very next thing that happens is that its data is freed and then the element is not removed from the cache, which frees the data again. This change sets obj->data to NULL to avoid the double-free. It also stops trying to resolve deltas after two continuous failed rounds of resolution, and adds a test for this.
* | | | | | | Merge pull request #4430 from tiennou/fix/openssl-x509-leakEdward Thomson2017-12-231-12/+17
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Free OpenSSL peer certificate
| * | | | | | | openssl: free the peer certificateEtienne Samson2017-12-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Per SSL_get_peer_certificate docs: ``` The reference count of the X509 object is incremented by one, so that it will not be destroyed when the session containing the peer certificate is freed. The X509 object must be explicitly freed using X509_free(). ```
| * | | | | | | openssl: merge all the exit paths of verify_server_certEtienne Samson2017-12-161-11/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes it easier to cleanup allocated resources on exit.
* | | | | | | | Merge pull request #4435 from lhchavez/ubsan-shift-overflowEdward Thomson2017-12-231-6/+6
|\ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | libFuzzer: Prevent a potential shift overflow
| * | | | | | | | Simplified overflow conditionlhchavez2017-12-151-3/+1
| | | | | | | | |
| * | | | | | | | Using unsigned insteadlhchavez2017-12-091-6/+8
| | | | | | | | |
| * | | | | | | | libFuzzer: Prevent a potential shift overflowlhchavez2017-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type of |base_offset| in get_delta_base() is `git_off_t`, which is a signed `long`. That means that we need to make sure that the 8 most significant bits are zero (instead of 7) to avoid an overflow when it is shifted by 7 bits. Found using libFuzzer.
* | | | | | | | | Merge pull request #4402 from libgit2/ethomson/iconvEdward Thomson2017-12-231-1/+1
|\ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | cmake: let USE_ICONV be optional on macOS
| * | | | | | | | | cmake: let USE_ICONV be optional on macOSethomson/iconvEdward Thomson2017-11-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of forcing iconv support on macOS (by forcing `USE_ICONV` on), honor the `USE_ICONV` option only on macOS. Although macOS includes iconv by default, some macOS users may have a deficient installation for some reason and they should be provided a workaround to use libgit2 even in this situation. iconv support is now disabled entirely on non-macOS platforms. No other platform supports core.precomposeunicode, and iconv should never be linked.
* | | | | | | | | | Merge pull request #4429 from novalis/delete-modify-submodule-mergeEdward Thomson2017-12-231-2/+5
|\ \ \ \ \ \ \ \ \ \ | |_|_|_|_|_|/ / / / |/| | | | | | | | | Do not attempt to check out submodule as blob when merging a submodule modify/deltete conflict
| * | | | | | | | | Do not attempt to check out submodule as blob when merging a submodule ↵David Turner2017-12-041-2/+5
| | |/ / / / / / / | |/| | | | | | | | | | | | | | | | | | | | | | | | | modify/deltete conflict
* | | | | | | | | Merge pull request #4447 from pks-t/pks/diff-file-contents-refcount-blobEdward Thomson2017-12-161-1/+3
|\ \ \ \ \ \ \ \ \ | |_|_|/ / / / / / |/| | | | | | | | diff_file: properly refcount blobs when initializing file contents
| * | | | | | | | diff_file: properly refcount blobs when initializing file contentsPatrick Steinhardt2017-12-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When initializing a `git_diff_file_content` from a source whose data is derived from a blob, we simply assign the blob's pointer to the resulting struct without incrementing its refcount. Thus, the structure can only be used as long as the blob is kept alive by the caller. Fix the issue by using `git_blob_dup` instead of a direct assignment. This function will increment the refcount of the blob without allocating new memory, so it does exactly what we want. As `git_diff_file_content__unload` already frees the blob when `GIT_DIFF_FLAG__FREE_BLOB` is set, we don't need to add new code handling the free but only have to set that flag correctly.
* | | | | | | | | Merge pull request #4432 from lhchavez/fix-missing-trailerPatrick Steinhardt2017-12-151-0/+4
|\ \ \ \ \ \ \ \ \ | |/ / / / / / / / |/| | | | | | | | libFuzzer: Fix missing trailer crash
| * | | | | | | | libFuzzer: Fix missing trailer crashlhchavez2017-12-081-0/+4
| | |_|_|_|_|_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change fixes an invalid memory access when the trailer is missing / corrupt. Found using libFuzzer.
* | | | | | | | stransport: provide error message on trust failuresEtienne Samson2017-12-141-1/+3
|/ / / / / / / | | | | | | | | | | | | | | Fixes #4440
* | | | | | | libFuzzer: Fix a git_packfile_stream leaklhchavez2017-12-061-0/+3
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change ensures that the git_packfile_stream object in git_indexer_append() does not leak when the stream has errors. Found using libFuzzer.
* | | | | | Merge pull request #4318 from Uncommon/amend_statusEdward Thomson2017-12-011-7/+12
|\ \ \ \ \ \ | | | | | | | | | | | | | | Add git_status_file_at
| * | | | | | status: Add a baseline field to git_status_options for comparing to trees ↵David Catmull2017-11-301-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | other than HEAD
* | | | | | | Merge pull request #4427 from pks-t/pks/openssl-threadidEdward Thomson2017-12-011-0/+9
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | openssl: fix thread-safety on non-glibc POSIX systems
| * | | | | | | openssl: fix thread-safety on non-glibc POSIX systemsPatrick Steinhardt2017-11-301-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the OpenSSL library provides all means to work safely in a multi-threaded application, we fail to do so correctly. Quoting from crypto_lock(3): OpenSSL can safely be used in multi-threaded applications provided that at least two callback functions are set, locking_function and threadid_func. We do in fact provide the means to set up the locking function via `git_openssl_set_locking()`, where we initialize a set of locks by using the POSIX threads API and set the correct callback function to lock and unlock them. But what we do not do is setting the `threadid_func` callback. This function is being used to correctly locate thread-local data of the OpenSSL library and should thus return per-thread identifiers. Digging deeper into OpenSSL's documentation, the library does provide a fallback in case that locking function is not provided by the user. On Windows and BeOS we should be safe, as it simply "uses the system's default thread identifying API". On other platforms though OpenSSL will fall back to using the address of `errno`, assuming it is thread-local. While this assumption holds true for glibc-based systems, POSIX in fact does not specify whether it is thread-local or not. Quoting from errno(3p): It is unspecified whether errno is a macro or an identifier declared with external linkage. And in fact, with musl there is at least one libc implementation which simply declares `errno` as a simple `int` without being thread-local. On those systems, the fallback threadid function of OpenSSL will not be thread-safe. Fix this by setting up our own callback for this setting. As users of libgit2 may want to set it themselves, we obviously cannot always set that function on initialization. But as we already set up primitives for threading in `git_openssl_set_locking()`, this function becomes the obvious choice where to implement the additional setup.
* | | | | | | | Merge pull request #4426 from pks-t/pks/diff-flag-set-fixEdward Thomson2017-11-302-8/+1
|\ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | diff_generate: fix unsetting diff flags
| * | | | | | | | diff_generate: fix unsetting diff flagsPatrick Steinhardt2017-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The macro `DIFF_FLAG_SET` can be used to set or unset a flag by modifying the diff's bitmask. While the case of setting the flag is handled correctly, the case of unsetting the flag was not. Instead of inverting the flags, we are inverting the value which is used to decide whether we want to set or unset the bits. The value being used here is a simple `bool` which is `false`. As that is being uplifted to `int` when getting the bitwise-complement, we will end up retaining all bits inside of the bitmask. As that's only ever used to set `GIT_DIFF_IGNORE_CASE`, we were actually always ignoring case for generated diffs. Fix that by instead getting the bitwise-complement of `FLAG`, not `VAL`.
| * | | | | | | | diff: remove unused macros `DIFF_FLAG_*`Patrick Steinhardt2017-11-301-7/+0
| |/ / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In commit 9be638ecf (git_diff_generated: abstract generated diffs, 2016-04-19), the code for generated diffs was moved out of the generic "diff.c" and instead into its own module. During that conversion, it was forgotten to remove the macros `DIFF_FLAG_IS_SET`, `DIFF_FLAG_ISNT_SET` and `DIFF_FLAG_SET`, which are now only used in "diff_generated.c". Remove those macros now.
* | | | | | | | winhttp: pass the same payload as ssh & http transports when checking ↵Etienne Samson2017-11-261-1/+1
|/ / / / / / / | | | | | | | | | | | | | | | | | | | | | certificates
* | | | | | | diff: expose the "indent heuristic" in the diff optionsCarlos Martín Nieto2017-11-191-0/+2
| |_|_|/ / / |/| | | | | | | | | | | | | | | | | | | | | | | We default to off, but we might want to consider changing `GIT_DIFF_NORMAL` to include it.
* | | | | | refcount: make refcounting conform to aliasing rulesPatrick Steinhardt2017-11-186-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Strict aliasing rules dictate that for most data types, you are not allowed to cast them to another data type and then access the casted pointers. While this works just fine for most compilers, technically we end up in undefined behaviour when we hurt that rule. Our current refcounting code makes heavy use of casting and thus violates that rule. While we didn't have any problems with that code, Travis started spitting out a lot of warnings due to a change in their toolchain. In the refcounting case, the code is also easy to fix: as all refcounting-statements are actually macros, we can just access the `rc` field directly instead of casting. There are two outliers in our code where that doesn't work. Both the `git_diff` and `git_patch` structures have specializations for generated and parsed diffs/patches, which directly inherit from them. Because of that, the refcounting code is only part of the base structure and not of the children themselves. We can help that by instead passing their base into `GIT_REFCOUNT_INC`, though.
* | | | | | signature: distinguish +0000 and -0000 UTC offsetsHenry Kleynhans2017-11-121-2/+7
| |_|/ / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Git considers '-0000' a valid offset for signature lines. They need to be treated as _not_ equal to a '+0000' signature offset. Parsing a signature line stores the offset in a signed integer which does not distinguish between `+0` and `-0`. This patch adds an additional flag `sign` to the `git_time` in the `signature` object which is populated with the sign of the offset. In addition to exposing this information to the user, this information is also used to compare signatures. /cc @pks-t @ethomson
* | | | | Merge pull request #4310 from pks-t/pks/common-parserEdward Thomson2017-11-118-943/+945
|\ \ \ \ \ | |_|/ / / |/| | | | Common parser interface
| * | | | config_parse: use common parser interfacePatrick Steinhardt2017-11-113-195/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As the config parser is now cleanly separated from the config file code, we can easily refactor the code and make use of the common parser module. This removes quite a lot of duplicated functionality previously used for handling the actual parser state and replaces it with the generic interface provided by the parser context.
| * | | | config_file: split out module to parse config filesPatrick Steinhardt2017-11-113-681/+746
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The configuration file code grew quite big and intermingles both actual configuration logic as well as the parsing logic of the configuration syntax. This makes it hard to refactor the parsing logic on its own and convert it to make use of our new parsing context module. Refactor the code and split it up into two parts. The config file code will only handle actual handling of configuration files, includes and writing new files. The newly created config parser module is then only responsible for parsing the actual contents of a configuration file, leaving everything else to callbacks provided to its provided function `git_config_parse`.
| * | | | parse: always initialize line pointerPatrick Steinhardt2017-11-112-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upon initializing the parser context, we do not currently initialize the current line, line length and line number. Do so in order to make the interface easier to use and more obvious for future consumers of the parsing API.
| * | | | parse: implement `git_parse_peek`Patrick Steinhardt2017-11-113-5/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some code parts need to inspect the next few bytes without actually consuming it yet, for example to examine what content it has to expect next. Create a new function `git_parse_peek` which returns the next byte without modifying the parsing context and use it at multiple call sites.
| * | | | parse: implement and use `git_parse_advance_digit`Patrick Steinhardt2017-11-113-19/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch parsing code has multiple recurring patterns where we want to parse an actual number. Create a new function `git_parse_advance_digit` and use it to avoid code duplication.
| * | | | patch_parse: use git_parse_contains_sPatrick Steinhardt2017-11-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of manually checking the parsing context's remaining length and comparing the leading bytes with a specific string, we can simply re-use the function `git_parse_ctx_contains_s`. Do so to avoid code duplication and to further decouple patch parsing from the parsing context's struct members.
| * | | | parse: extract parse modulePatrick Steinhardt2017-11-115-227/+269
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `git_patch_parse_ctx` encapsulates both parser state as well as options specific to patch parsing. To advance this state and keep it consistent, we provide a few functions which handle advancing the current position and accessing bytes of the patch contents. In fact, these functions are quite generic and not related to patch-parsing by themselves. Seeing that we have similar logic inside of other modules, it becomes quite enticing to extract this functionality into its own parser module. To do so, we create a new module `parse` with a central struct called `git_parse_ctx`. It encapsulates both the content that is to be parsed as well as its lengths and the current position. `git_patch_parse_ctx` now only contains this `parse_ctx` only, which is then accessed whenever we need to touch the current parser. This is the first step towards re-using this functionality across other modules which require parsing functionality and remove code-duplication.
* | | | | cmake: Allow user to select bundled zlibHenry Kleynhans2017-11-111-12/+16
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Under some circumstances the installed / system version of zlib may not be desirable due to being too old or buggy. This patch adds the option `USE_BUNDLED_ZLIB` that will cause the bundled version of zlib to be used. We may also want to add similar functionality to allow the user to select other bundled 3rd-party dependencies instead of using the system versions. /cc @pks-t @ethomson
* | | | Merge pull request #4308 from pks-t/pks/header-state-machineEdward Thomson2017-11-111-46/+82
|\ \ \ \ | | | | | | | | | | patch_parse: implement state machine for parsing patch headers
| * | | | patch_parse: fix parsing patches only containing exact renamesPatrick Steinhardt2017-09-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patches which contain exact renames only will not contain an actual diff body, but only a list of files that were renamed. Thus, the patch header is immediately followed by the terminating sequence "-- ". We currently do not recognize this character sequence as a possible terminating sequence. Add it and create a test to catch the failure.
| * | | | patch_parse: implement state machine for parsing patch headersPatrick Steinhardt2017-08-251-46/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Our code parsing Git patch headers is rather lax in parsing headers of a Git-style patch. Most notably, we do not care for the exact order in which header lines appear and as such, we may parse patch files which are not really valid after all. Furthermore, the state transitions inside of the parser are not as obvious as they could be, making it harder than required to follow its logic. To improve upon this situation, this patch introduces a real state machine to parse the patches. Instead of simply parsing each line without caring for previous state and the exact ordering, we define a set of states with their allowed transitions. This makes the patch parser more strict in only allowing valid successions of header lines. As the transition table is defined inside of a single structure with the expected line, required state as well as the state that we end up in, all state transitions are immediately obvious from just having a look at this structure. This improves both maintainability and eases reasoning about the patch parser.
* | | | | Merge pull request #4283 from tiennou/generic-tlsPatrick Steinhardt2017-11-0917-78/+137
|\ \ \ \ \ | | | | | | | | | | | | CMake: make HTTPS support more generic
| * | | | | cmake: move Darwin-specific block aroundEtienne Samson2017-10-231-9/+12
| | | | | | | | | | | | | | | | | | This allows us to only link against CoreFoundation when using the SecureTransport backend
| * | | | | cmake: Add USE_HTTPS as a CMake optionEtienne Samson2017-10-231-25/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It defaults to ON, e.g. "pick whatever default is appropriate for the platform". It accepts one of SecureTransport, OpenSSL, WinHTTP, or OFF. It errors if the backend library couldn't be found.
| * | | | | cmake: use FeatureSummary to display which features we end up usingEtienne Samson2017-10-231-0/+16
| | | | | |
| * | | | | cmake: make our macOS helpers more CMake-yEtienne Samson2017-10-231-14/+8
| | | | | |
| * | | | | https: correct some error messagesEtienne Samson2017-10-231-2/+2
| | | | | |
| * | | | | https: Prevent OpenSSL from namespace-leakingEtienne Samson2017-10-234-10/+23
| | | | | |
| * | | | | stream: Gather streams to src/streamsEtienne Samson2017-10-2315-28/+31
| | | | | |